Prevent widgets from exceeding width of container with border and padding


I would like to place a border around manually created containers in a sidebar to visually group widgets together (without requiring the submit button of st.form()). I can create the border using the method in this post - Applying custom CSS to manually created containers - but if I add padding the widgets protrude out the right of the container? Is there a way to adjust the width of the widgets so that they stay within the borders of the container, ideally with padding on each side? I have tried a three column layout as suggested in this post - Change width of selectbox - but the columns inherit the same border as the container. Example code snippet below. Thanks!

Steps to reproduce

Code snippet:

import streamlit as st

container1 = st.sidebar.container()

selectbox = container1.selectbox('Make a selection', ('A', 'B', 'C'))

slider = container1.select_slider('Left or Right?', options = ['Left', 'Right'])

# code  adapted from
    div[data-testid="stVerticalBlock"] div[style*="flex-direction: column;"] div[data-testid="stVerticalBlock"] {
        border: 1px solid black;
        border-radius: 2%;
        padding: 10px;

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.