I have a dropdown menu with items and I wanted to use the ODD and EVEN to alternate the colors. My question is...What's the CSS code for styling Dropdown list items please?
Use the CSS nth-child pseudo-class:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>HTML Dropdown list item baground colors</title>
<style type="text/css">
#myForm select option:nth-child(odd) {
color:black;
background:yellow;
}
#myForm select option:nth-child(even) {
color:white;
background:blue;
}
#myForm select {
background:green;
color:orange;
}
</style>
</head>
<body>
<form id="myForm" action="#" method="get">
<select>
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
<option>E</option>
<option>F</option>
</select>
</div>
</body>
</html>
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