Select dropdown option bold in chrome [duplicate]

2020-03-27 05:23发布

问题:

Is there any way to make an <option> tag bold in a select box in Chrome and IE using CSS? It's working in Firefox.

option.red {
    background-color: #cc0000; 
    font-weight: bold; 
    font-size: 12px; 
    color: white;
}
<select name="color">
    <option class="red" value="red">Red</option>
    <option value="white">White</option>
    <option value="blue">Blue</option>
    <option value="green">Green</option>
</select>

This is the same question as here, but there was no answer.

回答1:

You cannot do this. The most likely solution you'll find "out there" would be to add a surrounding span with hard coded style, but neither IE (7) nor Firefox (3.0.12) honor this.

What you can do is use a JavaScript solution to give you the appearance of a select without actually using a select.

And here's a great "howto" on how to do it: http://www.devirtuoso.com/2009/08/styling-drop-down-boxes-with-jquery/



回答2:

I used <option class="bold">Bold Text here</option>

with CSS:

option.bold {
     font-weight:bold;
}

and it worked for Firefox (Mac and Windows) and for IE11, but not for Chrome or Safari.



回答3:

Since Chrome doesn't allow bold font on option tag, you can use text-shadow property like

text-shadow: 0px 0px 0px black;

It will give same appearance of bold and work on all the browsers.