Skip to content

Instantly share code, notes, and snippets.

@yactouat
Last active September 16, 2023 05:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save yactouat/d575f387313250eb30d2781e52b87360 to your computer and use it in GitHub Desktop.
Save yactouat/d575f387313250eb30d2781e52b87360 to your computer and use it in GitHub Desktop.
a responsive mixin in SCSS
// 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