หลักการทำงานของการสืบทอดใน SASS
สาระสำคัญของการทำงานของคำสั่ง @extend ประกอบด้วย
การเพิ่มตัวเลือก (selector) ที่ต้องการขยายเข้าไปใน
ชุดสไตล์ใด ๆ ก็ตาม ที่มีตัวเลือกที่ถูกขยายอยู่
(ในตัวอย่างของเราคือ .warning):
พิจารณาตัวอย่าง:
.warning {
border: 1px solid;
background-color: #ffd900;
}
.warning .instruction {
background-image: url("/image/warning.png");
}
.personalWarning {
@extend .warning;
border-width: 3px;
}
ตอนนี้เรามาดูผลลัพธ์ของการคอมไพล์:
.warning, .personalWarning {
border: 1px solid;
background-color: #ffd900;
}
.warning .instruction, .personalWarning .instruction {
background-image: url("/image/warning.png");
}
.personalWarning {
border-width: 3px;
}
อธิบายว่าผลลัพธ์ของการคอมไพล์โค้ดต่อไปนี้จะเป็นอย่างไร:
#product-card p{
color: #460707;
padding: 10px;
}
#product-card-title {
@extend #product-card;
font-weight: 600px;
}
อธิบายว่าผลลัพธ์ของการคอมไพล์โค้ดต่อไปนี้จะเป็นอย่างไร:
.link .main-block{
font-size: 14px;
text-decoration: dashed;
}
.active-link {
@extend .link;
color: red;
}
อธิบายว่าผลลัพธ์ของการคอมไพล์โค้ดต่อไปนี้จะเป็นอย่างไร:
.link .main-block{
font-weight: bold;
text-decoration: none;
}
.active {
color: red;
}
.active-link {
@extend .link;
@extend .active;
}