Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Aurelian Spodarec
Aurelian Spodarec
10,801 Points

How do I make min width and max widht with Sass in a variable?

How do I make min width and max widht with Sass in a variable?

So i got usually $brk-small : '(min-width: 480px)'; but say i need to stop that on max-width 768px, how do i do it the Sass way? since sometimes i have to remove the nth-chidl(n2) for the desktop fomr the tables, which i need max-width for that.

2 Answers

Kevin Korte
Kevin Korte
28,149 Points

Hey Aurelian, check out this: https://css-tricks.com/approaches-media-queries-sass/

I think you'll really enjoy what the article goes over, and than use the one that you think works best for you. Good news is there is no right or wrong here as long as it gets you the results you need, in a way that makes sense. Remember the goal is to make your code easier to maintain, not add complexity to it. This article should break down a few techniques for you.

You could create a mixin with the desired media queries breakpoints you want i.e (480 px) and store those breakpoints into a variable. Then you could @include the mixin into different css styles.

//Media queries

@mixin mq($break) {
    @if $break == "phone" {
        @media (min-width: $brkpoint-xs) and (max-width: $brkpoint-sm) {
            @content;
        }
    }
    @else if $break == "plusPhone" {
        @media (min-width: $brkpoint-sm +1){
            @content;
        }
    }
    @else if $break == "tablet" {
        @media(min-width: $brkpoint-md + 1){
            @content;
        }

    }
    @else if $break == "desktop" {
        @media(min-width: $brkpoint-lg){
            @content;
        }
    }
    @else {
        @error "Error, No value could be retrieved for '#{$break}' "
    }
}
Aurelian Spodarec
Aurelian Spodarec
10,801 Points

Thank for that as well! Was actually looking at Modular Sass here at treehouse, not going thorw it all, but I just want to get the media queries right for now, step by step lol but that looks similar :)