Created
December 12, 2015 18:28
-
-
Save rikonor/ec17c76ade520f090779 to your computer and use it in GitHub Desktop.
Sass
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
@import "utils" | |
// Glboal breakpoints | |
$breakpoints: ( | |
small: 412px, | |
medium: 992px, | |
large: 1200px | |
); | |
// This is an extenstion of http://www.sitepoint.com/using-sass-maps/ | |
@mixin respond-to($breakpoint) { | |
@if map-has-key($breakpoints, $breakpoint) { | |
@media (min-width: #{map-get($breakpoints, $breakpoint)}) { | |
@content; | |
} | |
} | |
@else if $breakpoint == "default" { | |
@content; | |
} | |
@else if is-px($breakpoint) { | |
@media (min-width: #{$breakpoint}) { | |
@content; | |
} | |
} | |
} | |
@mixin bp-options($configKey, $config, $transform: keep-same) { | |
@each $configBreakpoint, $configValue in $config { | |
@include respond-to($configBreakpoint) { | |
#{$configKey}: call($transform, $configValue); | |
} | |
} | |
} |
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
// Given <X>px return true, otherwise return false | |
@function is-px($str) { | |
$tStr: quote($str); | |
@return str-index($tStr, px); | |
} | |
// Identity function | |
@function keep-same($val) { | |
@return $val; | |
} |
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
.element { | |
color: blue; | |
} | |
@media (min-width: 767px) { | |
.element { | |
color: yellow; | |
} | |
} | |
@media (min-width: 1000px) { | |
.element { | |
color: white; | |
} | |
} |
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
.element { | |
@include bp-options(color, ( | |
default: blue, | |
small: yellow, | |
1000px: white | |
)); | |
} |
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
.page { | |
min-height: calc(100vh - 45px); | |
} | |
@media (min-width: 767px) { | |
.page { | |
min-height: calc(100vh - 60px); | |
} | |
} |
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
// Let's assume we have a nav with a set of breakpoint specific heights | |
$navHeights: ( | |
default: 45px, | |
small: 60px | |
); | |
// We are interested in having another element's property be dependent on the nav height in the following way | |
@function page-min-height($navHeight) { | |
@return calc(100vh - $navHeight); | |
} | |
.page { | |
@include bp-options(min-height, $navHeights, page-min-height); | |
} | |
// In this way - if we change $navHeights, the .page min-height will automatically be adjusted as well |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment