Multiple extensions when applied @extend in SASS
Another interesting feature of using the @extend directive is that you can extend a single selector with more than one selector, i.e. it will inherit all styles:
Let's look at an example:
.warning {
border: 1px solid;
background-color: rgb(255, 217, 0);
}
.info {
font-size: 14px;
}
.personalWarning {
@extend .warning;
@extend .info;
border-width: 3px;
}
As a result of compilation we will get:
.warning, .personalWarning {
border: 1px solid;
background-color: #ffd900;
}
.info, .personalWarning {
font-size: 14px;
}
.personalWarning {
border-width: 3px;
}
It is important to know that multiple extensions can be written as a comma-separated list of selectors. For example, @extend .warning, .info; means the same as @extend .warning; @extend .info;
Tell me what the result of compiling the following code will be:
link {
font-size: 12px;
background-color: #ffd900;
}
button:active {
color: red;
}
.active-link {
@extend link;
@extend button:active;
text-decoration: wavy;
}
Tell me what the result of compiling the following code will be:
div {
font-size: 10px;
color: #181402;
}
.main-block {
border: 2px solid orange;
}
p {
padding: 5px;
}
#warning-text {
@extend div, .main-block, p;
margin-top: 10px;
}