Skip to content

Instantly share code, notes, and snippets.

@jasonkmccoy
Last active August 29, 2015 14:15
Show Gist options
  • Save jasonkmccoy/7fd63dc991b0f3b20929 to your computer and use it in GitHub Desktop.
Save jasonkmccoy/7fd63dc991b0f3b20929 to your computer and use it in GitHub Desktop.
Simple Mixin Example (Sass Bites Podcast #2)
/* 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;
}
/* 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)
/* 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);
}
<!-- Simple Mixin HTML Code -->
<div class="yes"><span>Yes</span></div>
<div class="no"><span>No</span></div>
@jasonkmccoy
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment