I used the st.markdown CSS hack to hide the Streamlit header, but there is still a thin white space on top. Do you know how to hide it too?
Additional context:
It is only noticeable when the sidebar is open.
Happens with Streamlit versions 1.8 and above.
Maybe it has something to do with the red decorator line that shows up by default, before hiding header.
Example code:
import streamlit as st
st.markdown("""
<style>
#MainMenu, header, footer {visibility: hidden;}
</style>
""",unsafe_allow_html=True)
st.title('This is a test app')
st.sidebar.markdown('After hiding streamlit header there is still a thin white space on top, noticeable when sidebar is open.')
Juan here, you replied on one of my Core PRs asking about this issue, and since it’s a slightly different thing than what I’m working on there, I wanted to reply here so we can fix this out
The issue you’re facing is related to the top: 2px and the height: calc(100vh - 2px) in the sidebar code. See screenshot below
You can remove that by adding the following to your custom CSS:
st.markdown("""
<style>
#MainMenu, header, footer {visibility: hidden;}
/* This code gets the first element on the sidebar,
and overrides its default styling */
section[data-testid="stSidebar"] div:first-child {
top: 0;
height: 100vh;
}
</style>
""",unsafe_allow_html=True)
Try it out and let me know! One thing to note though, is that these default styles you’re overriding are there to ensure your app works flawlessly, so please be mindful that changing this behavior might lead to other issues on your app.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.