hacks-guide-minimal-mistake.../_sass/mixins.scss

376 lines
12 KiB
SCSS
Raw Normal View History

2015-01-20 21:25:57 +01:00
/* ==========================================================================
Utility mixins
========================================================================== */
/*
Clearfix
For clearing floats like a boss h5bp.com/q
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin clearfix {
*zoom: 1;
&:before,
&:after {
display: table;
content: "";
2015-01-20 21:25:57 +01:00
/* Fixes Opera/contenteditable bug: */
/* http://nicolasgallagher.com/micro-clearfix-hack/#comment-36952 */
2014-07-31 19:09:32 +02:00
line-height: 0;
}
&:after {
clear: both;
}
}
2015-01-20 21:25:57 +01:00
/*
Webkit-style focus
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin tab-focus() {
2015-01-20 21:25:57 +01:00
/* Default */
2014-07-31 19:09:32 +02:00
outline: thin dotted #333;
2015-01-20 21:25:57 +01:00
/* Webkit */
2014-07-31 19:09:32 +02:00
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
2015-01-20 21:25:57 +01:00
/*
Center-align a block level element
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin center-block() {
display: block;
margin-left: auto;
margin-right: auto;
}
2015-01-20 21:25:57 +01:00
/* ==========================================================================
Typography related mixins
========================================================================== */
/*
Maintains vertical rhythm by setting a font-sizes proportional to
line-height and bottom margin
example: @font-size(16);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin font-size($size) {
font-size: 0px + $size;
font-size: 0rem + $size / $doc-font-size;
line-height: 0 + round($doc-line-height / $size*10000) / 10000;
margin-bottom: 0px + $doc-line-height;
margin-bottom: 0rem + ($doc-line-height / $doc-font-size);
}
2015-01-20 21:25:57 +01:00
/*
Just font-size (REMs + pixel fallback)
example: @include font-rem(16);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin font-rem($size) {
font-size: 0px + $size;
font-size: 0rem + $size / $doc-font-size;
}
2015-01-20 21:25:57 +01:00
/*
Just font-size (REMs + pixel fallback) and line-height
@include font(16);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin font($size) {
font-size: 0px + $size;
font-size: 0rem + $size / $doc-font-size;
line-height: 0 + round($doc-line-height / $size*10000) / 10000;
}
2015-01-20 21:25:57 +01:00
/*
Hide text overflow and end with ...
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin text-overflow() {
2015-01-20 21:25:57 +01:00
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* Indentation variable */
2014-07-31 19:09:32 +02:00
$indent-var: 0rem + ($doc-line-height / $doc-font-size);
2015-01-20 21:25:57 +01:00
/* ==========================================================================
Gradient mixins
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin horizontal($startColor : $white, $endColor : $lightergrey) {
2015-01-20 21:25:57 +01:00
background-color: $endColor;
background-image : -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
background-image : -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
background-image : -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
background-image : -ms-linear-gradient(left, $startColor, $endColor); // IE10
background-image : -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
background-image : linear-gradient(left, $startColor, $endColor); // W3C
background-repeat : repeat-x;
}
2014-07-31 19:09:32 +02:00
@mixin vertical($startColor : $white, $endColor: $lightergrey) {
2015-01-20 21:25:57 +01:00
background-image : -webkit-gradient(linear, 0 0, 0 100%, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
background-image : -webkit-linear-gradient(top, $startColor, $endColor); // Safari 5.1+, Chrome 10+
background-color : $endColor;
background-image : -moz-linear-gradient(top, $startColor, $endColor); // FF 3.6+
background-image : -ms-linear-gradient(top, $startColor, $endColor); // IE10
background-image : -o-linear-gradient(top, $startColor, $endColor); // Opera 11.10
background-image : linear-gradient(top, $startColor, $endColor); // W3C
background-repeat : repeat-x;
}
2014-07-31 19:09:32 +02:00
@mixin directional($startColor : $white, $endColor : $lightergrey, $deg : 45deg) {
2015-01-20 21:25:57 +01:00
background-color : $endColor;
background-image : -moz-linear-gradient($deg, $startColor, $endColor); // FF 3.6+
background-image : -ms-linear-gradient($deg, $startColor, $endColor); // IE10
background-image : -webkit-linear-gradient($deg, $startColor, $endColor); // Safari 5.1+, Chrome 10+
background-image : -o-linear-gradient($deg, $startColor, $endColor); // Opera 11.10
background-image : linear-gradient($deg, $startColor, $endColor); // W3C
background-repeat : repeat-x;
}
2014-07-31 19:09:32 +02:00
// .bordered(COLOR, COLOR, COLOR, COLOR);
@mixin bordered($top-color: #eee, $right-color: #eee, $bottom-color: #eee, $left-color: #eee) {
2015-01-20 21:25:57 +01:00
border-top : solid 1px $top-color;
border-left : solid 1px $left-color;
border-right : solid 1px $right-color;
border-bottom : solid 1px $bottom-color;
}
/* ==========================================================================
Rounded corners
========================================================================== */
2014-07-31 19:09:32 +02:00
2015-01-20 21:25:57 +01:00
/*
Round all corners
example: @include rounded(4px);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin rounded($radius:4px) {
2015-01-20 21:25:57 +01:00
border-radius : $radius;
}
/*
Round individual corners (top right, bottom right, bottom left, top left)
example: @include border-radius(4px, 0, 0, 4px);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin border-radius($topright: 0, $bottomright: 0, $bottomleft: 0, $topleft: 0) {
2015-01-20 21:25:57 +01:00
border-top-right-radius: $topright;
border-bottom-right-radius: $bottomright;
border-bottom-left-radius: $bottomleft;
border-top-left-radius: $topleft;
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
}
/*
Box shadow
example: @include box-shadow(HORIZONTAL VERTICAL BLUR COLOR));
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin box-shadow($shadow: 0 1px 3px rgba(0,0,0,.25)) {
2015-01-20 21:25:57 +01:00
-webkit-box-shadow: $shadow;
-moz-box-shadow: $shadow;
box-shadow: $shadow;
}
/*
Drop shadow
example: @include drop-shadow(HORIZONTAL, VERTICAL, BLUR, ALPHA);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin drop-shadow($x-axis: 0, $y-axis: 1px, $blur: 2px, $alpha: 0.1) {
2015-01-20 21:25:57 +01:00
-webkit-box-shadow: $x-axis $y-axis $blur rgba(0, 0, 0, $alpha);
-moz-box-shadow: $x-axis $y-axis $blur rgba(0, 0, 0, $alpha);
box-shadow: $x-axis $y-axis $blur rgba(0, 0, 0, $alpha);
}
/*
Text shadow
example: @include text-shadow(0 2px 3px rgba(0,0,0,.25));
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin text-shadow($shadow: 0 2px 3px rgba(0,0,0,.25)) {
2015-01-20 21:25:57 +01:00
text-shadow: $shadow; }
/*
Opacity
example: @include opacity(0.5); // 50% opacity
========================================================================== */
@mixin opacity($opacity: 0.5) {
opacity: $opacity;
}
2014-07-31 19:09:32 +02:00
2015-01-20 21:25:57 +01:00
/* ==========================================================================
Transformations
========================================================================== */
2014-07-31 19:09:32 +02:00
2015-01-20 21:25:57 +01:00
/*
@include rotate(VALUEdeg);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin rotate($deg) {
2015-01-20 21:25:57 +01:00
-webkit-transform: rotate($deg);
-moz-transform: rotate($deg);
-ms-transform: rotate($deg);
-o-transform: rotate($deg);
transform: rotate($deg);
}
/*
@include scale(VALUE);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin scale($ratio) {
2015-01-20 21:25:57 +01:00
-webkit-transform: scale($ratio);
-moz-transform: scale($ratio);
-ms-transform: scale($ratio);
-o-transform: scale($ratio);
transform: scale($ratio);
}
/*
@include skew(VALUE, VALUE);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin skew($x: 0, $y: 0) {
2015-01-20 21:25:57 +01:00
-webkit-transform: skew($x, $y);
-moz-transform: skew($x, $y);
-ms-transform: skew($x, $y);
-o-transform: skew($x, $y);
transform: skew($x, $y);
}
/*
@include transition(PROPERTY DURATION DELAY(OPTIONAL) TIMING-FINCTION);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin transition($transition) {
2015-01-20 21:25:57 +01:00
-webkit-transition: $transition;
-moz-transition: $transition;
-ms-transition: $transition;
-o-transition: $transition;
transition: $transition;
}
/*
@include translate(VALUE, VALUE);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin translate($x: 0, $y: 0) {
2015-01-20 21:25:57 +01:00
-webkit-transform: translate($x, $y);
-moz-transform: translate($x, $y);
-ms-transform: translate($x, $y);
-o-transform: translate($x, $y);
transform: translate($x, $y);
}
2014-07-31 19:09:32 +02:00
@mixin translate3d($x: 0, $y: 0, $z: 0) {
2015-01-20 21:25:57 +01:00
-webkit-transform: translate($x, $y, $z);
-moz-transform: translate($x, $y, $z);
-ms-transform: translate($x, $y, $z);
-o-transform: translate($x, $y, $z);
transform: translate($x, $y, $z);
}
2014-07-31 19:09:32 +02:00
@mixin animation($name, $duration: 300ms, $delay: 0, $ease: ease) {
-webkit-animation: $name $duration $delay $ease;
-moz-animation: $name $duration $delay $ease;
-ms-animation: $name $duration $delay $ease;
}
2015-01-20 21:25:57 +01:00
/* ==========================================================================
Background
========================================================================== */
/*
@include background-alpha(VALUE VALUE);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin background-alpha($color: $white, $alpha: 1) {
2015-01-20 21:25:57 +01:00
background-color: hsla(hue($color), saturation($color), lightness($color), $alpha);
}
/*
@include background-size(VALUE VALUE);
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin background-size($size){
2015-01-20 21:25:57 +01:00
-webkit-background-size: $size;
-moz-background-size: $size;
-o-background-size: $size;
background-size: $size;
}
/*
Box-sizing
example: @include box-sizing(VALUE); //(border-box, padding-box, content-box)
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin box-sizing($boxsize: border-box) {
2015-01-20 21:25:57 +01:00
-webkit-box-sizing: $boxsize;
-moz-box-sizing: $boxsize;
-ms-box-sizing: $boxsize;
box-sizing: $boxsize;
}
/* ==========================================================================
Image replacement
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin hide-text() {
2015-01-20 21:25:57 +01:00
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
/*
Hide from visual and speaking browsers
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin hidden {
display: none;
visibility: hidden;
}
2015-01-20 21:25:57 +01:00
/*
Hide but maintain layout
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin invisible() {
2015-01-20 21:25:57 +01:00
visibility: hidden;
}
/*
Resize
example: @include resize(VALUE); //(none, both, horizontal, vertical, inherit)
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin resize($direction: both) {
2015-01-20 21:25:57 +01:00
resize: $direction;
overflow: auto;
}
2014-07-31 19:09:32 +02:00
2015-01-20 21:25:57 +01:00
/*
Hidden but available to speaking browsers
========================================================================== */
2014-07-31 19:09:32 +02:00
@mixin visuallyhidden() {
2015-01-20 21:25:57 +01:00
overflow: hidden;
position: absolute;
clip: rect(0 0 0 0);
height: 1px;
width: 1px;
margin: -1px;
padding: 0;
border: 0; }