I have this play button and I would like to change the height of the button. I have search online and tried using the st.markdown method but it seems like the styling apply to all of my button in the page.
Do anyone know what is wrong? What does the first-child refer to?
The problem is that your css selector will select every button which is the first child of a div the class stButton, not the first such button on a page. In generate, the :first-* selectors refer to “the first child of a given element”. One option, which takes a bit of fiddling, is to select the nth element on the page, and style the button inside of that. For example, this styles only the PLAY button, but not the other two, because it’s a child of the 3rd element with the class element-container
import streamlit as st
st.markdown(
"""<style>
.element-container:nth-of-type(3) button {
height: 3em;
}
</style>""",
unsafe_allow_html=True,
)
st.button("STOP")
st.button("PLAY")
st.button("PAUSE")
Thank you for the reply. But how to find out
what is the nth-child position of an element given that I have other text Input and columns on the web app?
@qt.qt Unfortunately, I can’t think of a good way to do that programmatically, so if you used this method you would simply have to change the number until it was the correct button. Definitely not an ideal solution.
Hi @zimmer44, the trick is that if you have an f-string and you have {}s in it, it will assume they’re supposed to contain a valid python expression. The way around it is to double them up. For example:
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.