georad commited on
Commit
d98a4da
·
verified ·
1 Parent(s): 1945eeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -18
app.py CHANGED
@@ -1,31 +1,46 @@
1
  import streamlit as st
2
 
3
- # More specific CSS targeting for sticky header
 
 
 
 
 
 
4
  st.markdown("""
5
  <style>
6
- /* Target the main header container */
7
- [data-testid="stHeader"] {
8
- position: fixed;
9
- top: 0px;
10
- left: 0px;
11
- right: 0px;
12
- z-index: 1000;
13
  background-color: white;
14
- }
15
-
16
- /* Add padding to the main content to prevent it from being hidden under the header */
17
- [data-testid="stAppViewContainer"] > .main {
18
- padding-top: 3rem;
19
- }
20
-
21
- /* Ensure the sidebar isn't affected by the fixed header */
22
- [data-testid="stSidebar"] {
23
  z-index: 999;
24
- padding-top: 3rem;
 
 
 
 
 
25
  }
 
 
26
  </style>
27
  """, unsafe_allow_html=True)
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
 
31
 
 
1
  import streamlit as st
2
 
3
+ # Create a container for the sticky header
4
+ header_container = st.container()
5
+
6
+ # Create a separate container for the main content
7
+ main_container = st.container()
8
+
9
+ # Set up a custom CSS using st.markdown for the containers
10
  st.markdown("""
11
  <style>
12
+ div[data-testid="stVerticalBlock"] > div:nth-child(1) {
13
+ position: sticky;
14
+ top: 0;
 
 
 
 
15
  background-color: white;
 
 
 
 
 
 
 
 
 
16
  z-index: 999;
17
+ padding: 1rem;
18
+ border-bottom: 1px solid #f0f0f0;
19
+ }
20
+ /* Adjust main content padding */
21
+ div[data-testid="stVerticalBlock"] > div:nth-child(2) {
22
+ padding-top: 1rem;
23
  }
24
+ /* Hide default Streamlit header if desired */
25
+ header {visibility: hidden;}
26
  </style>
27
  """, unsafe_allow_html=True)
28
 
29
+ # Add content to the sticky header container
30
+ with header_container:
31
+ st.title("My App with Sticky Header")
32
+ # Add any other header elements here
33
+ st.markdown("---") # Optional divider
34
+
35
+ # Add content to the main container
36
+ with main_container:
37
+ # Your main app content goes here
38
+ st.write("Main content starts here")
39
+
40
+ # Add some sample content to demonstrate scrolling
41
+ for i in range(20):
42
+ st.write(f"Content line {i}")
43
+
44
 
45
 
46