Alignment of content

is there a way to hack alignment of content into streamlit? It would be great if we could align content within the main app-container, a st.container or a st.columns to the left/center/right.
I already found this issue on Github, but it doesn’t seem like this is on the radar at the moment: Content alignment option for Text elements · Issue #4109 · streamlit/streamlit · GitHub
Also this issue is related: Aligning of Streamlit widgets! · Issue #1799 · streamlit/streamlit · GitHub

Is there a way to somehow “hack” this behaviour using CSS?


import streamlit as st


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))

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.

Something like:
col1, inter_cols_pace, col2 = st.columns((2, 8, 2))

You’ll need to experiment as required.


Using the nth-of-type() selector (:nth-of-type() - CSS: Cascading Style Sheets | MDN) comes to mind to style only certain elements of the same class.

import streamlit as st


            border:1px solid red;

            border:1px solid blue;
            text-align: end;

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
with col3:
    ## Column 3
    This column was untouched by our CSS 

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. :slight_smile: 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:

Since you cannot nest columns, which would solve this problem, I was wondering whether this might be possible with some custom CSS?