How to use CSS to change font color in HTML based on tag text content-PHP Chinese Network Q&A
How to use CSS to change font color in HTML based on tag text content
P粉349222772
P粉349222772 2023-09-08 20:57:35
0
1
511

So I have a radio button with the text "Yes" and "No" and if any of them is selected I want the font color to change.

  • Yes (green)
  • No (red)

The following is the html code:

   

I have the following code in css that changes the label of the selected radio button:

input[type="radio"]:checked label { Font weight: bold! important; }

P粉349222772
P粉349222772

reply all (1)
P粉752479467

You can use block brackets to locate any property, including the "Text" property:

input[text="Yes"]:checked + label { color: green; } input[text="No"]:checked + label { color: red; }
   
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!