Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS "and" and "or"

People also ask

What does && mean in CSS?

&& works by stringing-together multiple selectors like-so: <div class="class1 class2"></div> div.class1.class2 { /* foo */ }

Can we use or in CSS selector?

No. CSS' or operator ( , ) does not permit groupings. It's essentially the lowest-precedence logical operator in selectors, so you must use .

How do I use multiple selectors in CSS?

Example# When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your style sheet. Use a comma to separate multiple grouped selectors. So the blue color applies to all <div> elements and all <p> elements.


&& works by stringing-together multiple selectors like-so:

<div class="class1 class2"></div>

div.class1.class2
{
  /* foo */
}

Another example:

<input type="radio" class="class1" />

input[type="radio"].class1
{
  /* foo */
}

|| works by separating multiple selectors with commas like-so:

<div class="class1"></div>
<div class="class2"></div>

div.class1,
div.class2
{
  /* foo */
}

AND (&&):

.registration_form_right input:not([type="radio"]):not([type="checkbox"])

OR (||):

.registration_form_right input:not([type="radio"]), 
   .registration_form_right input:not([type="checkbox"])

To select properties a AND b of a X element:

X[a][b]

To select properties a OR b of a X element:

X[a],X[b]

The :not pseudo-class is not supported by IE. I'd got for something like this instead:

.registration_form_right input[type="text"],
.registration_form_right input[type="password"],
.registration_form_right input[type="submit"],
.registration_form_right input[type="button"] {
  ...
}

Some duplication there, but it's a small price to pay for higher compatibility.