Why we can't style option of dropdown using CS

2019-07-11 18:23发布

问题:

This question already has an answer here:

  • How to style a <select> dropdown with only CSS? 24 answers

In Css we can genrally style all elements but I noticed that we can not style option element of a select using CSS. As far as I know Option is child element of select then what is possible causes that it don't let you style this element?

I've had reffered various answers on stackoverflow stating that You just can't style option. but I want to know exact reason behind it.

I've had reffered this link which says that option tag is rendered by OS and not by html. If so then why we need to specify option ? why it don't automattically render options.

Here is another link which shows how to style Select tag. But i want to know that why we can't style option? I don't want to know how to style select tag using CSS.

回答1:

You cannot style the option element because it is rendered by the OS, not HTML. That is why it can't be styled via CSS.

You can of course use some plug-in that replaces select with regular HTML elements that can be styled.



回答2:

There a duplicate method for this... its correct dropdown not accept the styling so you can make the thing which look like dropdown and give styling to that thing.. Here is the link of this explaination check Answer7

css style on select option