Centering an object with one weird trick! divs hate him

I came across a useful hack when trying to center an object (but didn’t want to use the unsafe markdown trick) using the new beta_columns:

import streamlit as st
import cv2
img = cv2.imread('photo.jpeg')

st.image(img, use_column_width=True, caption='Random image for sizing')
st.title("Off center :(")

col1, col2, col3 = st.beta_columns([1,1,1])
col2.title("Centered! :)")
col2.image(img, use_column_width=True)

The images are there to help see the placement in the sea of white space. Hope it helps someone out there!

3 Likes