I defined the pseudo class red:before
and red:after
, which contain a border-color hexcode. Now I need to switch the color from red to blue using another CSS class named blue
.
Here is my Html:
<div class="red blue">Text</div>
And this is my CSS:
.red:before, .red:after {
border-color: red;
}
How can I set the CSS for .blue
to make the border-color blue?
The proper way to override something in css in general all you have to do is to rewrite it again
.red:before, .red:after {
content: '';
width: 16px;
height: 16px;
border: 2px solid red /*we will override this*/
}
<div class="red blue">Text</div>
Now we override it
.red:before, .red:after {
content: '';
width: 16px;
height: 16px;
border: 2px solid red /*we will override this*/
}
.blue:before, .blue:after {
border: 2px solid blue
}
<div class="red blue">Text</div>
But you can clean this up like this
.red:before, .red:after {
content: '';
width: 16px;
height: 16px;
}
.red:before, .red:after {
border: 2px solid red
}
.blue:before, .blue:after {
border: 2px solid blue
}
<div class="red blue">Text</div>
A more specific rule should help:
div.blue:before, div.blue:after {
border-color: blue;
}
Reference: MDN - Specificity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With