georad commited on
Commit
b10eb94
·
verified ·
1 Parent(s): da577a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -26
app.py CHANGED
@@ -9,28 +9,27 @@ st.set_page_config(
9
  layout="wide" # Optional: Use wide layout
10
  )
11
 
12
- # --- Custom CSS for Sticky Default Header ---
13
  st.markdown("""
14
  <style>
15
  /* Target the default Streamlit header element */
16
  /* This is typically the <header> tag containing the title, menu, and status */
17
  header {
18
- position: sticky; /* Use sticky positioning */
19
- top: 0px; /* Stick to the top edge */
20
- z-index: 999; /* Ensure the header is always on top */
21
- background-color: rgb(255, 255, 255); /* Use white background or match Streamlit's default header color */
22
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Add shadow for better visibility */
23
- /* Ensure no conflicting height/overflow properties that might break sticky */
24
- height: auto; /* Allow height to adjust based on content */
25
- overflow: visible; /* Prevent content inside header from being clipped */
26
  }
27
 
28
- /* Add padding to the main content area to prevent it from starting behind the sticky header */
29
  /* This targets the main container div where your app content and pages are rendered */
30
- /* The exact value might need slight adjustment based on the header's actual height */
31
- /* Inspect the deployed app to confirm the header height and adjust padding-top accordingly */
32
  [data-testid="stAppViewContainer"] {
33
- padding-top: 60px; /* Estimate header height (~60px). Adjust if needed after inspection. */
34
  }
35
 
36
  /* Adjust padding for the sidebar content as well */
@@ -39,23 +38,16 @@ st.markdown("""
39
  }
40
 
41
  /* Ensure the main content block within the container also has correct top padding */
42
- /* This might be necessary for correct spacing below the header */
43
  .main .block-container {
44
  padding-top: 1rem; /* Keep or adjust default Streamlit content padding */
45
  }
46
 
47
- /* If the above 'header' sticky rule still doesn't work for the main scrollbar
48
- after adjusting padding-top, it strongly indicates a parent element issue.
49
- You would need to use browser dev tools to find which parent is breaking it
50
- and potentially try applying sticky to that parent, but that is more complex.
51
- For example, if a div wrapping the header and main content had overflow: auto:
52
- div[data-testid="some-parent-container"] {
53
- position: sticky;
54
- top: 0;
55
- z-index: 998; // Lower z-index than the header
56
- background: white;
57
- }
58
- This is hypothetical and requires DOM inspection.
59
  */
60
 
61
  </style>
 
9
  layout="wide" # Optional: Use wide layout
10
  )
11
 
12
+ # --- Custom CSS for Sticky Default Header (with !important) ---
13
  st.markdown("""
14
  <style>
15
  /* Target the default Streamlit header element */
16
  /* This is typically the <header> tag containing the title, menu, and status */
17
  header {
18
+ position: sticky !important; /* Force sticky positioning */
19
+ top: 0px !important; /* Force sticking to the top edge */
20
+ z-index: 999 !important; /* Force a high z-index */
21
+ background-color: rgb(255, 255, 255) !important; /* Force background color */
22
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Add shadow (usually doesn't need !important) */
23
+ /* Ensure no conflicting height/overflow properties */
24
+ height: auto !important; /* Force height to adjust */
25
+ overflow: visible !important; /* Force overflow visible */
26
  }
27
 
28
+ /* Add padding to the main content area to prevent it from starting behind the fixed header */
29
  /* This targets the main container div where your app content and pages are rendered */
30
+ /* Adjust this value based on the header's actual height after inspecting the deployed app */
 
31
  [data-testid="stAppViewContainer"] {
32
+ padding-top: 60px; /* Estimate header height (~60px). Adjust if needed. */
33
  }
34
 
35
  /* Adjust padding for the sidebar content as well */
 
38
  }
39
 
40
  /* Ensure the main content block within the container also has correct top padding */
 
41
  .main .block-container {
42
  padding-top: 1rem; /* Keep or adjust default Streamlit content padding */
43
  }
44
 
45
+ /* Ignore the data-testid="stMain" observation for the header stickiness,
46
+ as stMain is typically the main content area, not the header bar with status.
47
+ The sticky CSS should target the <header> tag.
48
+ If you confirmed the element you want sticky is truly not the <header> tag,
49
+ then the CSS selector above needs to be changed to target that specific element
50
+ and its parents examined for overflow/transform issues.
 
 
 
 
 
 
51
  */
52
 
53
  </style>