Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

SCSS @mixins vs @extend

SCSS @mixins:
  • Use mixins when you want to include a set of styles into multiple selectors or rules.
  • Mixins allow you to define reusable blocks of styles that can be included wherever needed.
  • They are useful for keeping your code DRY (Don't Repeat Yourself).
Example:

SCSS:
@mixin button-styles {
padding: 10px;
border: 1px solid #333;
background-color: #fff;
}

.button {
@include button-styles;
}

.another-button {
@include button-styles;
}
SCSS @extend:
  • Use @extend when you want one selector to inherit all the styles of another selector.
  • It helps in creating a relationship between selectors and avoids duplicating styles.
Example:

SCSS:
.button-styles {
padding: 10px;
border: 1px solid #333;
background-color: #fff;
}

.button {
@extend .button-styles;
}

.another-button {
@extend .button-styles;
}
When to use which:
  • Use @mixins when you have a set of styles that you want to reuse in different places.
  • Use @extend when you want one selector to inherit all the styles of another selector to avoid repeating styles.
Remember, both @mixins and @extend can be used, and the choice depends on your specific use case and the level of control you need over your styles. If you want more flexibility and control over where styles are applied, go for @mixins. If you want a direct relationship between selectors, use @extend.
 

New Threads

Buy us a coffee!

Back
Top Bottom