Skip to content

Instantly share code, notes, and snippets.

@djadriano
Last active October 19, 2015 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djadriano/8c6372e8e428eb282b51 to your computer and use it in GitHub Desktop.
Save djadriano/8c6372e8e428eb282b51 to your computer and use it in GitHub Desktop.
VW Mixins
/*
How to Use:
@include vw((padding-top, padding-bottom), 40px);
If needs rewrite some property, use:
@include vw((padding-top, padding-bottom), 40px, $min-vw: mq('laptop'));
*/
@mixin vw($property, $min-value, $max-value: $min-value, $min-vw: mq('mobile'), $max-vw: mq('tv')) {
& {
// If property is a list, loop the items and set the media queries
@if( type-of( $property ) == 'list' ) {
@each $item in $property {
@include fluid-vw-mq($min-vw, $max-vw, $min-value, $max-value, $item);
}
}
@if( type-of( $property ) == 'string' ) {
@include fluid-vw-mq($min-vw, $max-vw, $min-value, $max-value, $property);
}
}
}
@mixin fluid-vw-mq( $min-vw, $max-vw, $min-value, $max-value, $property ) {
@include min-screen($min-vw) {
#{$property}: calc(#{$min-value} + #{strip-unit($max-value - $min-value)} * ((100vw - #{$min-vw}) / #{strip-unit($max-vw - $min-vw)}));
}
@if( $max-value != $min-value ) {
@include min-screen($max-vw) {
#{$property}: $max-value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment