How can I center a picture?
This is the picture I normally displayed
But when I click the expand button, it will always be displayed on the left, rather than in the center of the screen. How can I center the image when I expand it?
How can I center a picture?
But when I click the expand button, it will always be displayed on the left, rather than in the center of the screen. How can I center the image when I expand it?
Hi there,
Thanks for sharing your question with the community! Please review our guidelines on how to post an effective question here – it looks like your post is missing a code snippet.
Caroline
I think the original question is about showing images centered while in fullscreen mode. For instance, the normal behavior is that:
import streamlit as st
"# Center an image when in fullscreen"
"Images (and most elements in general) are always aligned to the left"
st.image("https://placekitten.com/g/200/200")
But (if I understood the question correctly) this is the desired behavior:
I wonder if there is a better solution than the css selector I used here. It just targets images when a button whose title starts with “Exit” (as in “Exit Fullscreen”) is found before.
import streamlit as st
st.markdown(
"""
<style>
button[title^=Exit]+div [data-testid=stImage]{
text-align: center;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
}
</style>
""", unsafe_allow_html=True
)
"# Center an image when in fullscreen"
"Images (and most elements in general) are always aligned to the left"
st.image("https://placekitten.com/g/200/200")
I use this, and it works:
left_co, cent_co,last_co = st.columns(3)
with cent_co:
st.image(logo)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
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.
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.
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.
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.