By lai lin_forrest on Pinterest
Mobile first sass breakpoints config
Define breakpoints
$mobile: 480px;
$tablet: 768px;
$desktop: 1024px;
$large-desktop: 1280px;
Create a responsive mixin
@mixin minWidth($breakpoint) {
@if $breakpoint == "mobile" {
@media (min-width: #{$mobile}) {
@content;
}
} @else if $breakpoint == "tablet" {
@media (min-width: #{$tablet}) {
@content;
}
} @else if $breakpoint == "desktop" {
@media (min-width: #{$desktop}) {
@content;
}
} @else if $breakpoint == "large-desktop" {
@media (min-width: #{$large-desktop}) {
@content;
}
}
}
Use with @include
.element {
background-color: yellow; // Styles for mobile viewports
@include responsive("mobile") {
padding: 20px;
}
@include responsive("tablet") {
padding: 30px;
}
@include responsive("desktop") {
padding: 40px;
}
}
💡 TIP | this will compile to
.element {
background-color: yellow;
}
@media (min-width: 480px) {
.element {
padding: 20px;
}
}
@media (min-width: 768px) {
.element {
padding: 30px;
}
}
@media (min-width: 1024px) {
.element {
padding: 40px;
}
}
BONUS
easily convert px to rem
@use "sass:math";
@function rem($px) {
@return math.div($px, 16) + rem;
}