I want to apply the css only for the headings h2 which have no class. There are different classes with some h2 and some h2 has no class.
I have tried like this:
h2[class*=""]{
background: #cccccc;
}
But seems it's not working.
I want to apply the css only for the headings h2 which have no class. There are different classes with some h2 and some h2 has no class.
I have tried like this:
h2[class*=""]{
background: #cccccc;
}
But seems it's not working.
You can use like this:
h2:not([class]){
background: #cccccc;
}
The following will apply css to all h2
elements that do not have a class:
h2:not([class]) {
}
Its very simple actually. Try
h2
{
//css here
}
EDIT
For applying this for ONLY elements without classes, you have your answer here.
The problem in your code is that asterisk.
For example:
<ul>
<li class="class1">Hallo</li>
<li class="class2">Hallo</li>
<li>Hallo</li>
<li class="class3">Hallo</li>
<li>Hallo</li>
</ul>
This css, styles every li that has no class
li{
color:blue;
}
li:not([class]) {
color:red;
font-weight:bold;
}
For more information read here