Last active
April 18, 2020 03:26
-
-
Save jbrz0/6cce23d0fcf71bf57f4d01fba547fc43 to your computer and use it in GitHub Desktop.
Custom Sass mixin for using media queries
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
// Define the breakpoints | |
$breakpoint-small: 600px; | |
$breakpoint-med-small: 960px; | |
$breakpoint-med: 1175px; | |
@mixin screen($size, $type: max, $pixels: $breakpoint-small) { | |
@if $size == 'small' { | |
@media screen and ($type + -width: $breakpoint-small) { | |
@content; | |
} | |
} | |
@else if $size == 'med-small' { | |
@media screen and ($type + -width: $breakpoint-med-small) { | |
@content; | |
} | |
} | |
@else if $size == 'med' { | |
@media screen and ($type + -width: $breakpoint-med) { | |
@content; | |
} | |
} | |
@else if $size == 'large' { | |
@media screen and ($type + -width: $breakpoint-med) { | |
@content; | |
} | |
} | |
@else if $size == 'custom' { | |
@media screen and ($type + -width: $pixels + px) { | |
@content; | |
} | |
} | |
@else { | |
@content; | |
} | |
} | |
// Using the mixin | |
.foo { | |
@include screen(large) { | |
width: 20%; | |
} | |
@include screen(med) { | |
width: 40%; | |
} | |
@include screen(med-small) { | |
width: 60%; | |
} | |
@include screen(small) { | |
width: 80%; | |
} | |
@include screen(custom, max, 400) { | |
width: 100%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some better option: