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