Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore css class

Tags:

jquery

css

Can a css value be ignored ?

I have two divs :

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

<div id="div2" class="class1">
</div>

Can the css class be applied to just divs which are styled with class1 and if they contain class2 then its ignored ? So in above divs just div2 is styled with class1 because div1 is also styled with class2.

like image 510
blue-sky Avatar asked Aug 31 '12 13:08

blue-sky


People also ask

How do I override a parent CSS property?

To override the CSS properties of a class using another class, we can use the ! important directive. In CSS, ! important means “this is important”, and the property:value pair that has this directive is always applied even if the other element has higher specificity.

How do I ignore CSS code?

Sometimes you want to disable a part of the CSS code without deleting it. To do so you can put "/*" and "*/" around the code you want to disable.

How do I ignore a specific class in CSS?

In CSS, to exclude a particular class, we can use the pseudo-class :not selector also known as negation pseudo-class or not selector. This selector is used to set the style to every element that is not the specified by given selector. Since it is used to prevent a specific items from list of selected items.


4 Answers

You can use the :not selector. Here's an example:

CSS

.red:not(.yellow) {
    color: red;
}
.yellow {
    background-color: yellow;
}

HTML:

<div class = "red yellow">
   Glee's awesome!
</div>
<div class = "red">
   Glee's awesome!
</div>

Demo.

I hope that helped!

like image 63
Chris Avatar answered Oct 19 '22 01:10

Chris


Write like this:

.class1{
  background:red;
}
.class1.class2{
  background:none;
}
like image 35
sandeep Avatar answered Oct 19 '22 00:10

sandeep


You can use :not selector:

$('.class1:not(.class2)')
like image 25
undefined Avatar answered Oct 19 '22 00:10

undefined


YESSSS,

use !important after the css property

for example height:30px !important

if your class1 have height:30px and class2 height:40px then user !important in class2 height

like image 1
supersaiyan Avatar answered Oct 19 '22 01:10

supersaiyan