I have tried to bold the first option of the select box but it's only working in Firefox, not other browsers (Chrome, IE). Here is the code I've tried.
HTML
<select id="htmldisabled">
<option class="bold">test1</option>
<option>test2</option>
<option>test3</option>
<option>test4</option>
<option>test5</option>
<option>test6</option>
</select>
CSS
.bold {
font-weight:bold;
}
See demo at jsfiddle.
To bold the text in HTML, use either the strong tag or the b (bold) tag. Browsers will bold the text inside both of these tags the same, but the strong tag indicates that the text is of particular importance or urgency. You can also bold text with the CSS font-weight property set to “bold.”
The :first-of-type selector in CSS allows you to target the first occurence of an element within its container. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.
Definition and Usage. The <select> element is used to create a drop-down list. The <select> element is most often used in a form, to collect user input. The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the drop-down list will be submitted) ...
#htmldisabled:first-child{
font-weight:bold;
}
As you've discovered, it can't be done cross-browser ;)
Best to use a selectbox replacement script if you need special formatting or display
To my knowledge it doesnt work in IE unless you style the select
tag:
select{
font-weight:bold;
}
However this will influence all options. I dont know of another css-only solution, but would be interested in one as-well :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With