Advertisement
salmancreation

Mixin SCSS

Dec 9th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. Mixins
  2. Mixins let you create reusable snippets of code, which can be used in your code later. A good example of this is when we add a `border-radius` to an element. Typically we need also to include all the vendor prefixes too, which can be a pain. Well with our example mixin below you can see how we simply these to our CSS class, and mixins allow us to pass over the property too.
  3. @mixin border-radius($radius) {
  4. background-clip: padding-box; // prevents bg color from leaking outside the border
  5. -webkit-border-radius: $radius;
  6. -moz-border-radius: $radius;
  7. -ms-border-radius: $radius;
  8. -o-border-radius: $radius;
  9. border-radius: $radius;
  10. }
  11. .class {
  12. @include border-radius(4px);
  13. background: rgb(66,134,244);
  14. color: rgb(255,255,255);
  15. }
  16. would compile to:
  17. .class {
  18. background-clip: padding-box;
  19. -webkit-border-radius: 4px;
  20. -moz-border-radius: 4px;
  21. -ms-border-radius: 4px;
  22. -o-border-radius: 4px;
  23. border-radius: 4px;
  24. background: #4286f4;
  25. color: #ffffff;
  26. }
  27. Mixins are great; I will be creating an article in the future to discuss some of the ones I use personally in projects.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement