Let me preface this by saying the following is absolutely hard to maintain, even harder than the Markdown CSS Hack trick…
But yeah I’ve tried with CSS Selection alone but couldn’t find it out either. The only way of doing I found is by bypassing the components iframe:
import streamlit as st
import streamlit.components.v1 as components
a = st.number_input("value a", value=0.5)
b = st.number_input("value b", value=0.5)
c = st.number_input("value c", value=0.5)
components.html(
"""
<script>
const elements = window.parent.document.querySelectorAll('.stNumberInput div[data-baseweb="input"] > div')
console.log(elements)
elements[1].style.backgroundColor = 'red'
</script>
""",
height=0,
width=0,
)
I say unmaintainable because…well certain styles and events may break the moment you leave the iframe sandbox for components + well I think you can see from the code anytime you change the app, you’ll need to re-edit the code.
I don’t usually recommend this but just so you know there is this workaround…
Hey @andfanilo,
thanks for the quick reply. For the number input everything works fine. I tried to do the same for the selectbox but might not have the right variable name. I tried .stSelectBox instead of .stNumberInput but this doeas not work. Do you know what is the right variable to search for and is there a documentation where I can find all of them?
CSS hacks for the dumb? - #3 by andfanilo : you can use your devtools inspector tab to find the correct class. CSS Classes change every now and then between versions and it’s not something we are really supposed to play with so there’s no documentation on it
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.