with the code below, i was wondering how you do to personnalize the display : for example how do you add color and border to only container 1, add specific css for container 3 that we want to be a fix footer for example.
the st.info etc… are very usefull but limited as you cannot apply to a whole container for example. Otherwise when i use CSS it applies to all the 3 container.
Thanks for your help
Code snippet:
bloc1=st.container()
bloc2=st.container()
bloc3=st.container()
with bloc1:
st.write('This is container 1')
with bloc2:
col1,col2=st.columns((3,3))
with col1:
st.write("Let say Col1")
with col2:
st.write("here is Col2")
with bloc3:
st.write("this is actually my footer")
If you are careful to put everything in containers up to the point of custom formatting, you can get away with an nth-of-type selector.
import streamlit as st
with st.sidebar.container():
st.write('This is container 1.')
with st.sidebar.container():
st.write('This is container 2.')
with st.sidebar.container():
st.write('This is container 3.')
with st.sidebar.container():
st.write('This is container 4.')
side = st.sidebar.radio('Highlight Sidebar Container',[1,2,3,4])
with st.container():
st.write('This is container 1.')
with st.container():
st.write('This is container 2.')
with st.container():
st.write('This is container 3.')
with st.container():
st.write('This is container 4.')
body = st.radio('Highlight Body Container',[1,2,3,4])
st.markdown('#### Be sure nothing is mixed in with the containers up until the nth one '\
'you are trying to format. The introduction of some other div will '\
'mess of the index to the nth container.')
css_sidebar_container = f'''
<style>
[data-testid="stSidebarNav"] + div [data-testid="stVerticalBlock"] div:nth-of-type({side})
[data-testid="stVerticalBlock"] {{background-color:rgba(175,238,238,.2);}}
</style>
'''
css_body_container = f'''
<style>
[data-testid="stSidebar"] + section [data-testid="stVerticalBlock"] div:nth-of-type({body})
[data-testid="stVerticalBlock"] {{background-color:rgba(175,238,238,.2)}}
</style>
'''
css_radio = '''
<style>
[role="radiogroup"] {flex-direction: row;}
</style>
'''
st.markdown(css_sidebar_container,unsafe_allow_html=True)
st.markdown(css_body_container,unsafe_allow_html=True)
st.markdown(css_radio,unsafe_allow_html=True)
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.