/    Sign up×
Community /Pin to ProfileBookmark

Font styles in select box

I’ve done a bit of searching and come up with a few threads on changing the background color of an option in a select box but nothing on how one might be able to change the font style on a per option basis.

I am currently using the following set, which works fine for coloring but if I add font-weight:bold; into the select.highlight selector it does nothing (it still colors the options but does not make the text bold)

[code=php]
<style type=”text/css”>
select {
width:100px;
}

select.highlight {
background-color:red;
}
</style>

<select name=”choos”>
<option class=”highlight” value=”1″>One</option>
<option value=”2″>Two</option>
<option class=”highlight” value=”3″>Three</option>
<option value=”4″>Four</option>
</select>
[/code]

Any ideas? Answers on a postcard ?

to post a comment
CSS

6 Comments(s)

Copy linkTweet thisAlerts:
@JayDieJun 02.2004 — I guess you can't change the font-family or style of an option in a select object... Yes, you can change the (background)color of the option, but you can't change something of the font...
Copy linkTweet thisAlerts:
@FangJun 02.2004 — You do not have class="highlight" in your select.
Copy linkTweet thisAlerts:
@OhLordyauthorJun 02.2004 — Ooops, typo. There was supposed to be a space between the "select" and the ".highlight".
Copy linkTweet thisAlerts:
@FangJun 02.2004 — There is no class in your select. That is why it doesn't work.
Copy linkTweet thisAlerts:
@OhLordyauthorJun 02.2004 — Ah, so you can't change the font on a per option basis?
Copy linkTweet thisAlerts:
@FangJun 02.2004 — &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;DOM table&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;style type="text/css"&gt;
select {
width:100px;
background:red;
font : bold larger Algerian;
}
option.highlight {
background-color:green;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;select name="choos"&gt;
&lt;option class="highlight" value="1"&gt;One&lt;/option&gt;
&lt;option value="2"&gt;Two&lt;/option&gt;
&lt;option class="highlight" value="3"&gt;Three&lt;/option&gt;
&lt;option value="4"&gt;Four&lt;/option&gt;
&lt;/select&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @OhLordy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...