Matthew Layton
Matthew Layton

Reputation: 42260

SASS inheritance - omiting the base class

I can use this syntax for inheriting a class in SASS

Code

.message {
  border: 1px solid #ccc;
  padding: 10px;
  color: #333;
}

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

Output

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

.success {
  border-color: green;
}

I want to do something similar, whereby .message is omitted from the output

Desired Output

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

.success {
  border-color: green;
}

Is this possible?

Upvotes: 0

Views: 166

Answers (1)

user4994625
user4994625

Reputation:

Yes, using placeholder selector:

SASS

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

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

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

OUTPUT

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

.success {
  border-color: green;
}

.error {
  border-color: red;
}

The problem is if you want message like a class, then you have to extend too:

.message{
  @extend %message;
}

Upvotes: 1

Related Questions