1

Are these equivalent:-

selector[attr1="val1"] [attr2="val2"] {
  property: value;
}

Select a {selector} which has a attribute called [attr1] that has the exact value of "val1", AND also the same {selector} which has a attribute called [attr2] that has the exact value of "val2". Since the logical operator is "AND", any one condition being wrong will make the selector fail.

selector[attr1="val1"], selector[attr2="val2"] {
 property: value;
}

This one uses grouping. Can I assume the same for the later as I did for the former?

1 Answer 1

1

No, the comma is more like an OR, it will select targets with either attribute 1 or attribute 2 or both

Sign up to request clarification or add additional context in comments.

4 Comments

p, h1 {color: red;} - select "p" AND "h1"?
This will make "p" AND "h1" = color:red?
Yes, read reference.sitepoint.com/css/selectorgrouping, it will affect both of them, it is a logical OR
If it was a logical AND it would only affect elements that were both p and h1 (which is not valid anyway)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.