π¨Β Β Styleable Container
Submitted by Lukas Masuch
Summary
A container that allows to style its child elements using CSS.
Functions
stylable_container
Insert a container into your app which you can style using CSS. This is useful to style specific elements in your app.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
The key associated with this container. This needs to be unique since all styles will be applied to the container with this key. |
required |
css_styles |
str | List[str]
|
The CSS styles to apply to the container elements. This can be a single CSS block or a list of CSS blocks. |
required |
Returns:
Name | Type | Description |
---|---|---|
DeltaGenerator |
'DeltaGenerator'
|
A container object. Elements can be added to this container using either the 'with' notation or by calling methods directly on the returned object. |
Source code in src/streamlit_extras/stylable_container/__init__.py
Import:
- You should add this to the top of your .py file
Examples
example
def example():
with stylable_container(
key="green_button",
css_styles="""
button {
background-color: green;
color: white;
border-radius: 20px;
}
""",
):
st.button("Green button")
st.button("Normal button")
with stylable_container(
key="container_with_border",
css_styles="""
{
border: 1px solid rgba(49, 51, 63, 0.2);
border-radius: 0.5rem;
padding: calc(1em - 1px)
}
""",
):
st.markdown("This is a container with a border.")