Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mixins
- 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.
- @mixin border-radius($radius) {
- background-clip: padding-box; // prevents bg color from leaking outside the border
- -webkit-border-radius: $radius;
- -moz-border-radius: $radius;
- -ms-border-radius: $radius;
- -o-border-radius: $radius;
- border-radius: $radius;
- }
- .class {
- @include border-radius(4px);
- background: rgb(66,134,244);
- color: rgb(255,255,255);
- }
- would compile to:
- .class {
- background-clip: padding-box;
- -webkit-border-radius: 4px;
- -moz-border-radius: 4px;
- -ms-border-radius: 4px;
- -o-border-radius: 4px;
- border-radius: 4px;
- background: #4286f4;
- color: #ffffff;
- }
- 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