SCSS Nesting Question

jackharner

Jack Harner 🚀

Posted on January 10, 2019

SCSS Nesting Question

Hi SCSS Peeps! I'm trying to get in the habit of writing better cleaner SCSS, and I need some feedback.

Given the following (simplified) mix-in to generate media queries in SCSS:

@mixin breakpoint($point) {
    @if $point==desktop {
        @media (min-width: 70em) {
            @content ;
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Example A

Do you nest a Parent and Child selector like this:

.parent {

    // Parent Mobile Styles

    .child {
        // Child Mobile Styles
    }

    @include breakpoint(desktop) {

        // Parent Desktop Stlyes

        .child {
            // Child Desktop Styles
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Example B

or like this:

.parent {
    // Parent Mobile Styles

    @include breakpoint(desktop) {
        // Parent Desktop Styles 
    }

    .child {
        // Child Mobile Styles

        @include breakpoint(desktop) {
            // Parent Desktop Styles
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Or something totally different? One of my problems is I need to pick one way to handle media queries and stick with it. Any suggestions?

💖 💪 🙅 🚩
jackharner
Jack Harner 🚀

Posted on January 10, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

SCSS Nesting Question
scss SCSS Nesting Question

January 10, 2019