I adapted this from @Marc’s Awesome Streamlit Resources app.
BACKGROUND_COLOR = 'white'
COLOR = 'black'
def set_page_container_style(
max_width: int = 1100, max_width_100_percent: bool = False,
padding_top: int = 1, padding_right: int = 10, padding_left: int = 1, padding_bottom: int = 10,
color: str = COLOR, background_color: str = BACKGROUND_COLOR,
):
if max_width_100_percent:
max_width_str = f'max-width: 100%;'
else:
max_width_str = f'max-width: {max_width}px;'
st.markdown(
f'''
<style>
.reportview-container .sidebar-content {{
padding-top: {padding_top}rem;
}}
.reportview-container .main .block-container {{
{max_width_str}
padding-top: {padding_top}rem;
padding-right: {padding_right}rem;
padding-left: {padding_left}rem;
padding-bottom: {padding_bottom}rem;
}}
.reportview-container .main {{
color: {color};
background-color: {background_color};
}}
</style>
''',
unsafe_allow_html=True,
)