Can we add class attribute in option element?

前端 未结 4 1557
一生所求
一生所求 2020-12-20 17:45

I want to add class for my option element. Is that valid to add class attribute in HTML option element?

4条回答
  •  自闭症患者
    2020-12-20 18:20

    The class attribute is valid for option according to the relevant part of the HTML 4.01 Recommendation. The HTML5 drafts, including HTML5 CR, are even more permissive: they allow class literally on any element.

    My guess is that what you really wanted to ask was whether you can style some option elements differently from others, using class attributes and CSS. Then the answer is that this depends on browser – not due to problems with recognizing class attributes but due to implementations of that are partly immune to CSS as regards to styling items in a dropdown list.

提交回复
热议问题