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: