Created
June 1, 2023 08:34
-
-
Save hungdev/1faf6a60ec86b54e536c758dfbc18de1 to your computer and use it in GitHub Desktop.
a responsive mixin in SCSS
This file contains hidden or 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
// SO responsive mixin | |
// a mixin is different from a function as it does not return a value but serves as placeholder for code | |
@mixin responsive( $breakpoint ) { | |
/* | |
breakpoints are viewport arbitrary values, | |
they are defined with the aim of allowing the SCSS/CSS code of your app' behave accordingly to your user's device width, | |
the breakpoints I used were inspired by Bootstrap => | |
https://getbootstrap.com/docs/5.0/layout/breakpoints/ | |
*/ | |
@if $breakpoint == smartphone-portrait { | |
@media only screen and ( max-width: 575.98px ) { | |
@content; | |
} | |
} | |
@if $breakpoint == smartphone-landscape { | |
@media only screen and ( min-width: 575.99px ) and ( max-width: 767.98px ) { | |
@content; | |
} | |
} | |
@if $breakpoint == tablet { | |
@media only screen and ( min-width: 767.99px ) and ( max-width: 1199.97px ) { | |
@content; | |
} | |
} | |
@if $breakpoint == laptop { | |
@media only screen and ( min-width: 1199.98px ) and ( max-width: 1399.98px ) { | |
@content; | |
} | |
} | |
@if $breakpoint == desktop { | |
@media only screen and ( min-width: 1399.99px ) { | |
@content; | |
} | |
} | |
} | |
// EO responsive mixin | |
//example of how to use the mixin in your SCSS code (inside a given selector) | |
// .myCLass { | |
// @include responsive(smartphone-portrait) { | |
// font-size: 15px; | |
//} | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment