Hi,
I’m trying to make only certain sections of my Streamlit app display wider without setting the entire app to layout="wide"
. I’d like to maintain the standard layout for most of the app but have specific sections or containers (like st.columns()
or st.container()
) expand to 80-95% of the total allowable viewport width.
Here’s what I’ve tried so far:
- Using custom CSS to set
width
andmax-width
onst.container()
or specificdiv
elements. - Targeting Streamlit’s internal
data-testid
attributes likestVerticalBlock
andstHorizontalBlock
to apply custom width styles. - Wrapping the sections in custom HTML
div
containers with inline CSS to control the width.
Unfortunately, none of these approaches have provided a reliable solution. The CSS styles are either overridden by Streamlit’s default settings, or they apply inconsistently. Ideally, I’d like to be able to:
- Set a custom width (e.g., 80-90%) for certain
st.container()
orst.columns()
blocks. - Maintain the standard width for other sections of the app.
Has anyone successfully managed to make only part of a Streamlit app wider? Any tips, workarounds, or examples would be greatly appreciated!
Example Code of What I’ve Tried:
import streamlit as st
# Attempt to make only a certain section wider using custom CSS
st.markdown("""
<style>
.custom-container {
width: 90% !important;
max-width: 1200px !important;
margin: auto;
padding: 20px;
border: 2px solid blue; /* For testing */
}
</style>
<div class="custom-container">
""", unsafe_allow_html=True)
# Content within the custom wider container
st.subheader("Custom Wider Section")
col1, col2, col3 = st.columns(3)
with col1:
st.write("Left Column")
with col2:
st.write("Center Column")
with col3:
st.write("Right Column")
# Close the custom container
st.markdown("</div>", unsafe_allow_html=True)
# Regular Streamlit width for other content
st.subheader("Back to Normal Width")
st.write("This part should remain at the default width.")