I use LESS and here is my example:
.arrow{
color: red;
}
.arrow:before{
content: ">";
}
.button{
background: blue;
.arrow;
&:before{
border: 1px solid;
}
}
And this is CSS after parsing:
.button{
background: blue;
color: red;
}
.button:before{
border: 1px solid; // HERE IS NO content: ">" !!!
}
How to add :before
pseudo-element from .arrow
class to my button?
Adding multiple pseudo elementsYou can combine several CSS pseudo-elements for one element. However, you cannot use CSS ::after two times or ::before two times. In the example below, the first letter of <div> is green and has x-large font size.
A pseudo-class is a selector that selects elements that are in a specific state, e.g. they are the first element of their type, or they are being hovered over by the mouse pointer.
A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, the pseudo-class :hover can be used to select a button when a user's pointer hovers over the button and this selected button can then be styled.
Combining pseudo classes with CSS classesIt is possible to combine pseudo classes and regular CSS classes. This combination lets you style elements that have specific classes and also react to certain external factors.
You can use the extend
option like below. It basically applies all properties of the arrow
class to the button
class also. The all
keyword means the child classes are also extended.
LESS:
.button{
background: blue;
&:extend(.arrow all);
&:before{
border: 1px solid;
}
}
Compiled CSS:
.arrow,
.button {
color: red;
}
.arrow:before,
.button:before {
content: ">";
}
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