Last active
August 29, 2015 14:15
-
-
Save jasonkmccoy/7fd63dc991b0f3b20929 to your computer and use it in GitHub Desktop.
Simple Mixin Example (Sass Bites Podcast #2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CSS Output */ | |
/* Example 1 */ | |
div { | |
display: inline-block; | |
width: 200px; | |
height: 200px; | |
} | |
span { | |
margin: 20px; | |
position: relative; | |
top: 40px; | |
left: 40px; | |
text-align: center; | |
padding: 20px; | |
} | |
.yes { | |
background: red; | |
display: inline-block; | |
} | |
.no { | |
background: blue; | |
} | |
.yes { | |
color: black; | |
font-size: 1em; | |
} | |
/* Example 2 */ | |
.yes { | |
background: red; | |
} | |
.no { | |
background: blue; | |
} | |
.no { | |
color: black; | |
font-size: 1em; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sass Code */ | |
/* General div/span styles */ | |
div | |
display: inline-block | |
width: 200px | |
height: 200px | |
span | |
margin: 20px | |
position: relative | |
top: 40px | |
left: 40px | |
text-align: center | |
padding: 20px | |
/* Example 1: Yes */ | |
%yes-extend | |
// yes background is red | |
background: red | |
display: inline-block | |
=my-mixin($value1, $value2: 1em, $value3: true) | |
// if $value3:true, color will be red | |
// if $value3:false, color will be blue | |
color: $value1 | |
font-size: $value2 | |
@if $value3 | |
@extend %yes-extend | |
@else | |
@extend %no-extend | |
.yes | |
+my-mixin(black) | |
/* Example 2: No Example */ | |
%no-extend | |
// no background color is blue | |
background: blue | |
=my-mixin($value1, $value2: 1em, $value3: false) | |
color: $value1 | |
font-size: $value2 | |
@if $value3 | |
@extend %yes-extend | |
@else | |
@extend %no-extend | |
.no | |
+my-mixin(black) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* SCSS Code */ | |
/* General div/span styles */ | |
div { | |
display: inline-block; | |
width: 200px; | |
height: 200px; | |
} | |
span { | |
margin: 20px; | |
position: relative; | |
top: 40px; | |
left: 40px; | |
text-align: center; | |
padding: 20px; | |
} | |
/* Example 1: Yes */ | |
%yes-extend { | |
// yes background is red | |
background: red; | |
display: inline-block; | |
} | |
@mixin my-mixin($value1, $value2:1em, $value3:true) { | |
// if $value3:true, color will be red | |
// if $value3:false, color will be blue | |
color: $value1; | |
font-size: $value2; | |
@if $value3 { @extend %yes-extend; } | |
@else { @extend %no-extend; } | |
} | |
.yes { | |
@include my-mixin(black); | |
} | |
/* Example 2: No Example */ | |
%no-extend { | |
// no background color is blue | |
background: blue; | |
} | |
@mixin my-mixin($value1, $value2:1em, $value3:false) { | |
color: $value1; | |
font-size: $value2; | |
@if $value3 { @extend %yes-extend; } | |
@else { @extend %no-extend; } | |
} | |
.no { | |
@include my-mixin(black); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Simple Mixin HTML Code --> | |
<div class="yes"><span>Yes</span></div> | |
<div class="no"><span>No</span></div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sass Bites Podcast #2
https://www.youtube.com/watch?v=yA647_8cUQI
https://www.youtube.com/user/sassbites