might be best explain with an example: say I want to change the border to red instead of black after I made a selection.
here’s the link to sample code: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select
on page load, the dropdown list has a "normal" border around it.
after I made a selection, the border-width seems to have doubled.
I thought the CSS might be a pseudo-class but looking at this list (https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes), I cannot see anything that might be suitable.
2
Answers
To achieve the desired effect of changing the border color of a select element after a selection is made, you can use the :valid pseudo-class along with some CSS. Here’s an example:
The style you’re seeing does not come as a direct consequence of having made a selection. You obviously have opened the
select
using a mouse or trackpad, otherwise (using the keyboard) you’d have noticed the style already before opening it.What you’re seeing is the
focus
styles of theselect
element.To change it, use e.g. this CSS:
If you really want a different styling based on the user having made a selection, you’ll either need JavaScript to detect a "dirty" state, or modify the markup in ways probably not intended like suggested in the other answer.