Created
November 19, 2014 06:46
-
-
Save maximhoffman/9161157227b78d3fbe11 to your computer and use it in GitHub Desktop.
Sass mixins
This file contains 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
// @include box-sizing(border-box); | |
@mixin box-sizing($type) { | |
-webkit-box-sizing:$type; | |
-moz-box-sizing:$type; | |
box-sizing:$type; | |
} | |
// @include opacity(0.5); | |
@mixin opacity($opacity) { | |
opacity: $opacity; | |
filter: alpha(opacity=($opacity * 100)); | |
} | |
// @include column-width(150px); | |
@mixin column-width ( $value: 150px ) { | |
-webkit-column-width: $value; | |
-moz-column-width: $value; | |
column-width: $value; | |
} | |
// @include circle(); | |
@mixin circle { | |
@include border-radius(100%); | |
} | |
// @include font-size(14px); | |
@mixin font-size($size) { | |
font-size:$size; | |
font-size: ($size / 16px) * 1rem; | |
} | |
// @include box-shadow(8px, 8px); | |
@mixin box-shadow( $h: 10px , $v: 10px , $b: 0px , $s: 0px , $c: #000000 ) { | |
-webkit-box-shadow: $h $v $b $s $c; | |
-moz-box-shadow: $h $v $b $s $c; | |
box-shadow: $h $v $b $s $c; | |
} | |
// @include xPos(50px); | |
@mixin xPos($x) { | |
-webkit-transform:translateX($x); | |
-moz-transform:translateX($x); | |
-ms-transform:translateX($x); | |
transform:translateX($x); | |
} | |
// @include vertical-align(); | |
@mixin vertical-align { | |
position: relative; | |
top: 50%; | |
-webkit-transform: translateY(-50%); | |
-ms-transform: translateY(-50%); | |
transform: translateY(-50%); | |
} | |
// @include flexbox(); | |
@mixin flexbox { | |
display:-webkit-box; // old | |
display:-moz-box; // old | |
display:-ms-flexbox; // ie | |
display:-webkit-flex; // new | |
display:flex; // new | |
} | |
// @include flex(1, 2); | |
@mixin flex($values) { | |
-webkit-box-flex: $values; | |
-moz-box-flex: $values; | |
-ms-flex: $values; | |
-webkit-flex: $values; | |
flex: $values; | |
} | |
// @include flex-order(3); | |
@mixin flex-order($order){ | |
-webkit-box-ordinal-group: $order; // old | |
-moz-box-ordinal-group: $order; // old | |
-ms-flex-order: $order; // ie | |
-webkit-order: $order; // new | |
order: $order; // new | |
} | |
// @include flex-direction(column); | |
@mixin flex-direction($direction) { | |
@if $direction == column { | |
-webkit-flex-direction:vertical; | |
-moz-flex-direction:vertical; | |
-ms-flex-direction:column; | |
-webkit-flex-direction:column; | |
flex-direction:column; | |
} | |
@else { | |
-webkit-flex-direction:horizontal; | |
-moz-flex-direction:horizontal; | |
-ms-flex-direction:row; | |
-webkit-flex-direction:row; | |
flex-direction:row; | |
} | |
} | |
// @include gradient(#ff00ff, #ff00cc, vertical); | |
@mixin gradient($start-color, $end-color, $orientation) { | |
background: $start-color; | |
@if $orientation == vertical { | |
// vertical | |
background: -moz-linear-gradient(top, $start-color 0%, $end-color 100%); | |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,$start-color), color-stop(100%,$end-color)); | |
background: -webkit-linear-gradient(top, $start-color 0%,$end-color 100%); | |
background: -o-linear-gradient(top, $start-color 0%,$end-color 100%); | |
background: -ms-linear-gradient(top, $start-color 0%,$end-color 100%); | |
background: linear-gradient(to bottom, $start-color 0%,$end-color 100%); | |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='$start-color', endColorstr='$end-color',GradientType=0 ); | |
} | |
@else if $orientation == horizontal { | |
// horizontal | |
background: -moz-linear-gradient(left, $start-color 0%, $end-color 100%); | |
background: -webkit-gradient(linear, left top, right top, color-stop(0%,$start-color), color-stop(100%,$end-color)); | |
background: -webkit-linear-gradient(left, $start-color 0%,$end-color 100%); | |
background: -o-linear-gradient(left, $start-color 0%,$end-color 100%); | |
background: -ms-linear-gradient(left, $start-color 0%,$end-color 100%); | |
background: linear-gradient(to right, $start-color 0%,$end-color 100%); | |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='$start-color', endColorstr='$end-color',GradientType=1 ); | |
} | |
@else { | |
// radial | |
background: -moz-radial-gradient(center, ellipse cover, $start-color 0%, $end-color 100%); | |
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,$start-color), color-stop(100%,$end-color)); | |
background: -webkit-radial-gradient(center, ellipse cover, $start-color 0%,$end-color 100%); | |
background: -o-radial-gradient(center, ellipse cover, $start-color 0%,$end-color 100%); | |
background: -ms-radial-gradient(center, ellipse cover, $start-color 0%,$end-color 100%); | |
background: radial-gradient(ellipse at center, $start-color 0%,$end-color 100%); | |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='$start-color', endColorstr='$end-color',GradientType=1 ); | |
} | |
} | |
// @include ghost-button(“Trebuchet”, 12px, #ffffff, 5px, #34dec6, 4px, 300ms, #000000 ); | |
@mixin ghost-button($font, $font-size, $font-color, $border-size, $border-color, $padding, $transition-speed, $hover-color) { | |
display:inline-block; | |
text-decoration:none; | |
text-transform:uppercase; | |
font-family: $font; | |
font-size: $font-size; | |
color:$font-color; | |
border:$border-size solid $border-color; | |
padding:$padding; | |
-webkit-transition: color $transition-speed, background $transition-speed; | |
transition: color $transition-speed, background $transition-speed; | |
&:hover { | |
background:$border-color; | |
color:$hover-color; | |
} | |
} | |
// Breakpoint | |
// By using the @content statement, we can even pull in content, and set up all our break points by keyword. You shouldn’t set break points based on devices, but for the sake of clarity here’s one for desktop and mobile: | |
//div { | |
// margin:5em; | |
// @include break-point(mobile) { | |
// margin:2em; | |
// } | |
//} | |
@mixin break-point($point) { | |
@if $point == desktop{ | |
@media only screen and (max-width:50em) { | |
@content; | |
} | |
} | |
@else if $point == mobile { | |
@media only screen and (max-width:20em) { | |
@content; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment