Reputation: 563
How to add CSS 'content' to the 'option' tag? I would like to achieve e.g: "Name: Volvo".
<html>
<head>
<style>
option:before {
content: "Name: ";
}
</style>
</head>
<body>
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
</body>
</html>
Upvotes: 1
Views: 333
Reputation: 10975
Unfortunately, pseudo-elements don't work for image, input, select options.
One option is to wrap select inside and div and use :before
content
<body>
<div>
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
</div>
</body>
CSS:
div::before{
content:"Name: "
}
https://codepen.io/nagasai/pen/PRwreg
Other option is to use javascript or jQuery to add content "Name:"
Upvotes: 2