PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 9, 2022

[FIXED] What CSS selector syntax finds multiple pseudo classes on the same element?

 November 09, 2022     css, html, pseudo-class     No comments   

Issue

What CSS selector finds all unchecked and disabled checkboxes? Those links provide answers to how to find unchecked or disabled checkboxes, respectively, and this question shows how to find an element with one pseudo-class and one pseudo-element, but I'm looking to find multiple pseudo classes on the same element.

I think the answer is to chain them without spaces (i.e., input[type="checkbox"]:disabled:not(:checked), and this seems to work, but I don't know how to tell if this is working correctly or doing something else and returning what I want by coincidence.


Solution

'this seems to work' - no it doesn't as it picks up those checkboxes that are checked. Put a :not in and you'll be OK.

input[type="checkbox"]:disabled:not(:checked)

Here's a snippet showing the various combinations. cyan is what your code would select and pink is the one you actually want.

input[type="checkbox"]:disabled:checked+label {
  background: cyan;
}

input[type="checkbox"]:disabled:not(:checked)+label {
  background: pink;
}
<input type="radio" checked><label>Radio checked</label>
<input type="radio"><label>Radio unchecked not disabled</label>
<input type="checkbox"><label>Checkbox not checked not disabled</label>
<input type="checkbox" disabled><label>Checkbox not checked disabled</label>
<input type="checkbox" checked><label>Checkbox checked not disabled</label>
<input type="checkbox" checked disabled><label>Checkbox checked disabled</label>



Answered By - A Haworth
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing