How to style the options of the HTML "select" element?
P粉208469050
P粉208469050 2023-08-20 12:33:38
0
2
446
<p>This is my HTML code: </p> <pre class="brush:php;toolbar:false;"><select id="ddlProducts" name="ddProducts"> <option>Product 1: Electronic products</option> <option>Product 2: Sporting Goods</option> </select></pre> <p>I want to bold the product names (i.e. 'Product 1', 'Product 2', etc.) and italicize their categories (i.e. Electronics, Sporting Goods, etc.) using CSS. I found an old question mentioning that it's not possible using HTML and CSS, but hopefully there is a solution now. </p>
P粉208469050
P粉208469050

reply all(2)
P粉156532706

No, this is not possible because the styling of these elements is handled by the user's operating system. MSDN will answer your questions here:

P粉825079798

Only a few style attributes can be applied to <option> elements.

This is because this type of element is an example of a "replacement element". They are operating system dependent and not part of HTML/browser. It cannot be styled via CSS.

There are alternative plugins/libraries that look like <select>, but are actually made of regular HTML elements that can be styled.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!