Skip to content

Instantly share code, notes, and snippets.

@procload
Last active December 17, 2015 09:19
Show Gist options
  • Save procload/5586140 to your computer and use it in GitHub Desktop.
Save procload/5586140 to your computer and use it in GitHub Desktop.
Handy dandy SASS mixins. Some I wrote myself, others I've modified and the rest I've taken. Enjoy.
// MATH & LAYOUT
// --------------------------------------------------
@function calc-em($target-px, $context: $base-font-size) {
@return ($target-px / $context) * 1em;
}
/* One-true layout hack for equal height columns */
@mixin equalize-column {
margin-bottom: -99999px;
padding-bottom: 99999px;
}
// Must be using Susy grid
%container {
@include container;
}
// Clearfix
%group {
*zoom:1;
&:before,
&:after {
visibility: hidden;
display: block;
font-size: 0;
content: ".";
clear: both;
height: 0;
}
}
// Absolute Positioning
@mixin abs-pos ($top: auto, $right: auto, $bottom: auto, $left: auto) {
top: $top;
right: $right;
bottom: $bottom;
left: $left;
position: absolute;
}
// MEDIA QUERIES
// --------------------------------------------------
// Assumes you want IE 8 and below to use largest screen size
@mixin respond-to($viewport-width, $ie-version: 'lt-ie9') {
@media only screen and (min-width: $viewport-width) {
@content;
}
@if $ie-version == 'lt-ie9' {
html.lt-ie9 & { // Using Paul Irish's conditional comments
@content;
}
}
@else if $ie-version == 'lt-ie8' {
html.lt-ie8 & { // Using Paul Irish's conditional comments
@content;
}
}
}
// Retina Image
@mixin image-2x($image, $width, $height) {
@media (min--moz-device-pixel-ratio: 1.3),
(-o-min-device-pixel-ratio: 2.6/2),
(-webkit-min-device-pixel-ratio: 1.3),
(min-device-pixel-ratio: 1.3),
(min-resolution: 1.3dppx) {
/* on retina, use image that's scaled by 2 */
background-image: url($image);
background-size: $width $height;
}
}
// TYPOGRAPHY
// --------------------------------------------------
// Replace logo with text
@mixin replace-text($width, $height, $background-details) {
text-indent: -9999px;
white-space: nowrap;
overflow: hidden;
display: block;
width: $width;
height: $height;
background: $background-details;
}
// Creates ellipsis for overflow text
@mixin ellipsis() {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
// ANIMATIONS
// --------------------------------------------------
@mixin keyframes($name) {
@-webkit-keyframes #{$name} {
@content
}
@-moz-keyframes #{$name} {
@content
}
@-ms-keyframes #{$name} {
@content
}
@-o-keyframes #{$name} {
@content
}
@keyframes #{$name} {
@content
}
}
@mixin animation($value) {
-webkit-animation: $value;
-moz-animation: $value;
-ms-animation: $value;
-o-animation: $value;
animation: $value;
}
// Usage
// **************************************************
/*
@include keyframes(move) {
0% { left: 0; }
100% { left: 100px; }
}
.box {
@include animation(move 0.5s ease infinite alternate);
}
*/
// IE HACKS
// --------------------------------------------------
@mixin ie7 {
* + html & { // Using browser hacks
@content;
}
}
@mixin ie8 {
html.ie8 & { // Using Paul Irish's conditional comments
@content;
}
}
@mixin ie9 {
html.ie9 & { // Using Paul Irish's conditional comments
@content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment