Is there a way to somehow “hack” this behaviour using CSS?
MWE:
import streamlit as st
st.set_page_config(layout='wide')
col1, col2 = st.columns(2)
with col1:
st.markdown('Some markdown on the left')
with col2:
st.button('Some button on the right') # -> how to align this button to the far right?
Hi @Wally , you could probably define 3 columns as below:
col1, inter_cols_pace, col2 = st.columns((x, y, z))
Where:
x is the width that your markdown content requires.
y is the width that your button requires, and
inter_cols_pace is the width of the space you require in-between the 2 column outputs.
import streamlit as st
st.set_page_config(layout='wide')
st.markdown(
"""
<style>
div[data-testid="column"]:nth-of-type(1)
{
border:1px solid red;
}
div[data-testid="column"]:nth-of-type(2)
{
border:1px solid blue;
text-align: end;
}
</style>
""",unsafe_allow_html=True
)
col1, col2, col3 = st.columns(3)
with col1:
"""
## Column 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Volutpat sed cras ornare arcu dui vivamus.
"""
with col2:
"""
## Column 2
Stuff aligned to the right
"""
st.button("➡️")
with col3:
"""
## Column 3
This column was untouched by our CSS
"""
st.button("🐈")
Hi @edsaac,
sorry for replying late, yet thank you very much. That solved the problem for me or at least gave me some inspiration as to how to tackle this problem. I was able to right align a single st.button within a column.
Related question:
Is it even possible to align two streamlit widgets side-by-side within a st.column using CSS? Like so:
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.