in HTML by (1.7k points)

 Explain what is a @extend directive used for in Sass?

1 Answer

0 votes
by (1.7k points)

Using @extend lets you share a set of CSS properties from one selector to another. It helps keep your Sass very dry.

Consider:

%message-shared {
  border: 1px solid #ccc;
  padding: 10px;
  color: #333;
}

.message {
  @extend %message-shared;
}

.success {
  @extend %message-shared;
  border-color: green;
}

.error {
  @extend %message-shared;
  border-color: red;
}

.warning {
  @extend %message-shared;
  border-color: yellow;
}

CSS output:

.message, .success, .error, .warning {
  border: 1px solid #cccccc;
  padding: 10px;
  color: #333;
}

.success {
  border-color: green;
}

.error {
  border-color: red;
}

.warning {
  border-color: yellow;
}

Related questions

+1 vote
asked Aug 17, 2020 in HTML by RShastri (1.7k points)
+1 vote
asked Aug 17, 2020 in HTML by RShastri (1.7k points)
+1 vote
asked Aug 17, 2020 in HTML by RShastri (1.7k points)
0 votes
asked Aug 17, 2020 in HTML by RShastri (1.7k points)
+1 vote
asked Aug 17, 2020 in HTML by RShastri (1.7k points)
0 votes
asked Apr 13, 2022 in VueJS by john ganales (14.0k points)
0 votes
asked Jan 15, 2020 in Angular by rahuljain1 (6.5k points)
...