When I run my app locally the CSS to change the st.selectbox focus color isn’t loaded, but when I refresh it is. Does anyone know why and how I can fix it?
Thanks for sharing this question! Have you tried loading the CSS file as early as possible in your script to make sure it applied before any elements are rendered?
Another option could be to add the CSS code directly to the main page of the script rather than importing it.
Unfortunately I tried both but with the same result. The loading of the CSS is placed directly under the imports with this question, then there is a logic class and then the rest of the page elements. If I put the CSS in the page file itself the result is the same.
Try checking the developer tools in your browser to see which CSS rules are taking precedence. Maybe adding something like “!important” would help to get the rules you want to be applied first. Or maybe the focus is not being set until after the CSS rules load.
I do think I have the right selectors otherwise the CSS also wouldn’t load after the reload, same with “!important”. I’m not sure what you mean with the focus not being set, can you elaborate?
I run the application with “streamlit run main.py” and then I have the red border, and if I click the refresh button in my edge browser I get the blue border.
I do the same and the blue border never appears for me.
Not that I had to define a couple of undefined names (machine_id_filters and UILogic IIRC) in order to make your code run. You will have them defined in a different way that may trigger different behavior.
I’m not sure if that has any impact. “machine_id_filters” are a few random number to show options, and the UILogic.get_index is a method to get the index of the selected option so it would show the value after an option is selected and the machine_id_filters en filtered to only inlcude options that match the already selected filters.
I am not sure either, but the most (only?) obvious difference between what I run and what you run is the code I cannot see, so in my view it is the main suspect.
No, not just when the selectbox has the focus. Unfortunately my css sucks and I couldn’t find any example.
But if you can see the blue border you must be almost there. I am still missing a piece, though, because I cannot see it.
My CSS is only working after a refresh, the same goes for my theming. I don’t think the rest of my code is related because it’s either logic code or different streamlit element for on the page unless maybe the way I created the app or maybe the architecture which looks like this:
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.