Home >Web Front-end >CSS Tutorial >Can CSS Style `` Elements Like `:checked` Styles Checkboxes?
Can CSS :selected Pseudo Class Style Selected
The
The :selected pseudo class works similarly to the :checked pseudo class for input elements, which applies to checkbox and radio inputs when they are checked. In the case of
To style the selected option, you can use the following code:
option:selected { background-color: red; }
Note, however, that styling the color may not be supported in all browsers.
Additionally, a unique use case of this functionality is hiding the selected item from the dropdown list:
option:checked { display: none; }
This code hides the selected option from the dropdown, leaving only the placeholder text visible.
The above is the detailed content of Can CSS Style `` Elements Like `:checked` Styles Checkboxes?. For more information, please follow other related articles on the PHP Chinese website!