Home >Web Front-end >CSS Tutorial >How do I change the text color of a specific `` within a `` element?
In an HTML document, CSS can be used to modify the appearance of individual options within a drop-down menu (
The key solution lies in setting the desired color property directly to the specific option. In this case, the "gray" color was achieved by assigning a style attribute with a color value to the first
<code class="html"><option style="color: gray" value="null">Select one option</option></code>
To ensure that all other options remained unaffected, a class, such as "others," can be applied to them and overridden with a different color:
<code class="css">.others { color: black; }</code>
By using this approach, the first option can be selectively styled without altering the colors of the following options, resulting in the desired effect.
The above is the detailed content of How do I change the text color of a specific `` within a `` element?. For more information, please follow other related articles on the PHP Chinese website!