Skip to content

Instantly share code, notes, and snippets.

@nikola-wd
Last active April 12, 2020 19:41
Show Gist options
  • Select an option

  • Save nikola-wd/9f0902aaf353c0cef6515da746b10a8f to your computer and use it in GitHub Desktop.

Select an option

Save nikola-wd/9f0902aaf353c0cef6515da746b10a8f to your computer and use it in GitHub Desktop.
[Media Queries Scss Mixin] - SASS Mixin #sass #scss #mixin
// 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;
}
}
// TO USE MIXIN, WRITE
.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