Drive this star and like the Twitter' And Facebook', Do not forget to subscribe and comment us And share the video And the channelQ:
Why does the CSS rule assigned to the attribute need to be more specific than the attribute?
I was reading this article and got confused by the following
For example, if the CSS rule were:
.menu-item:hover {
color: #000;
}
the color property of the hover property of an HTML element would not be able to access that property.
If this is the case, why does the more specific CSS rule not have to be more specific than the attribute selector? What's the difference in my example between these two?
A:
The effect of having the more specific style override the less specific style is to suppress the less specific style. That is, if a rule applies, then the rule is used instead of the other style.
So if you want to have both styles apply, then you need to use both.
A:
From What’s the difference between a selector and an attribute selector?
A selector usually contains elements, while an attribute selector contains attributes.
So, when you use CSS properties to style elements, then you can’t use both the element selector and attribute selector together, because element selector is more specific than the attribute selector.
This means, if you have the selector
.menu-item {
color: red;
font-size: 16px;
}
and you add the attribute to the class, like this
.menu-item[type=text] {
color: blue;
}
then the new css will be
.menu-item[type=text] {
color: blue;
}
.menu-item {
color: red;
font-size: 16px;
}
which means, only.menu-item[type=text] will have an effect.
Det er fredag aften og forventningen om stormvejr i Danmark er betydeligt højere end sidste år, men ifølge DMI er skyerne derimod ikke af den her type.
Indtil middag p ac619d1d87
Related links:
Comments