DEV Community

Kashif Raza
Kashif Raza

Posted on

1

Mixin Approaches for Media Queries with Sass

Sass mixins give us the ability to create reusable chunks of code they reduce repetition, promote dry code & allow for ease of maintenance. Writing media queries as mixins to inject into your stylesheets, wherever they’re required — makes a whole lot of sense! Lets take a look at an example..

Setup mixins

@mixin for-size($size) {
@if $size == phone-only {
@media (max-width: 375px) { @content; }
}@else if $size == mobile-small {
@media (max-width: 480px) { @content; }
}@else if $size == max-mobile {
@media (max-width: 767px) { @content; }
}@else if $size == tablet-landscape-up {
@media (max-width: 991px) { @content; }
}@else if $size == tablet-landscape-up {
@media (max-width: 1024px) { @content; }
}@else if $size == desktop-up {
@media (max-width: 1200px) { @content; }
} @else if $size == big-desktop-up {
@media (min-width: 1600px) { @content; }
}
}

Using Mixin

.header-title {

font-size: 2rem;

@include for-size(phone-only) {

font-size: 1rem;
}
}

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay