Last active
January 2, 2016 11:39
-
-
Save sebald/8298301 to your computer and use it in GitHub Desktop.
Lazy breakpoints and IE8 fallback for SCSS.
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
// Vars (I put these in a _globals.scss with all my other variables) | |
// ------------------------ | |
$breakpointTiny: 580; | |
$breakpointSmall: 790; | |
$breakpointNormal: 1200; | |
// Breakpoint Mixin | |
// ------------------------ | |
$oldie: false !default; | |
// Mixin to add specific styles to older browsers, namely IE8. | |
@mixin oldie { | |
@if $oldie { | |
// Wrap the oldies. | |
.oldie & { | |
@content; | |
} | |
} | |
} | |
@mixin breakpoint($type) { | |
$width: 0 !default; | |
// Get width from globals. | |
@if $type == tiny { | |
$width: $breakpointTiny; | |
} | |
@else if $type == small { | |
$width: $breakpointSmall; | |
} | |
@else if $type == normal { | |
$width: $breakpointNormal; | |
} | |
// Test if type is at least a number. | |
@else if round($type) == $type { | |
$width: $type | |
} | |
// Else throw a meaningful warning. | |
@else { | |
@warn "Breakpoint param is neither a knoown var nor is it a number!"; | |
} | |
// Add media query for $width and oldies. | |
@media (min-width: em($width)) { @content; } | |
// Create styles for oldies? | |
@if $oldie { | |
@if $oldie >= $width { | |
// Wrap the oldies. | |
// .oldie & { | |
@include oldie { | |
@content; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With vars
With numbers (px)
Fallback for older browsers
E.g. setting
$oldie:
to1024
will generate.oldie
styles for media queries equal and larger than 1024px.