Home >Web Front-end >CSS Tutorial >How to Change the Text Color of a Specific `` within a `` Dropdown?
When attempting to modify the text color of the first option in a dropdown list, you may encounter difficulties using CSS classes. Here's a solution:
To change the color of the first option only, apply an inline style directly to that option:
<code class="html"><option style="color: grey" value="null">select one option</option></code>
This approach ensures that the style applies only to the first option, leaving the remaining options with their default black color.
To further customize the style of the other options, create a CSS class named "others":
<code class="css">.others { color: black; }</code>
Then, add the "others" class to the remaining options:
<code class="html"><option value="1" class="others">one</option> <option value="2" class="others">two</option></code>
This will set all options except the first one to black. The combination of inline styling and CSS class ensures that the first option remains grey while the others are black.
The above is the detailed content of How to Change the Text Color of a Specific `` within a `` Dropdown?. For more information, please follow other related articles on the PHP Chinese website!