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:
style.scss.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:
style.css.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;
Задание 1
Tell me what the result of compiling the following code will be:
styles.scsslink {
font-size: 12px;
background-color: #ffd900;
}
button:active {
color: red;
}
.active-link {
@extend link;
@extend button:active;
text-decoration: wavy;
}
Задание 2
Tell me what the result of compiling the following code will be:
styles.scssdiv {
font-size: 10px;
color: #181402;
}
.main-block {
border: 2px solid orange;
}
p {
padding: 5px;
}
#warning-text {
@extend div, .main-block, p;
margin-top: 10px;
}