Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using mixin grid-media-query for multiple breakpoints #70

Open
ericrovtar opened this issue May 13, 2014 · 4 comments
Open

Using mixin grid-media-query for multiple breakpoints #70

ericrovtar opened this issue May 13, 2014 · 4 comments

Comments

@ericrovtar
Copy link

I'm guessing I know the answer, but is there a way to use the mixin grid-media-query to render a block of styles for multiple breakpoints. For example, if I want styles for the desk and lap breakpoints.

Thanks!

@Cleecanth
Copy link

Adding an extra each statement in the grid-media-query mixin will accomplish this.

@mixin grid-media-query($media-queries){
    $breakpoint-found: false;

    @each $media-query in $media-queries {

        @each $breakpoint in $breakpoints{
            $name: nth($breakpoint, 1);
            $declaration: nth($breakpoint, 2);

            @if $media-query == $name and $declaration{
                $breakpoint-found: true;

                @media only screen and #{$declaration}{
                    @content;
                }
            }
        }
    }

    @if $breakpoint-found == false{
        @warn "Breakpoint '#{$media-query}‚' does not exist"
    }
}

From there, you can just declare:

@include grid-media-query((palm, lap)){
    //  Your code here...
}

@KittyGiraudel
Copy link
Contributor

Actually this won't work because you still have a single argument in the mixin signature, but you pass it 2 arguments when including it.

Either you have to turn $media-queries into an arglist (like this: @mixin grid-media-query($media-queries...)), or you have to wrap your arguments with braces when including it to pass a single list to the mixin (like this: @include grid-media-query((palm, lap)).

@Cleecanth
Copy link

Hugo is right. I've since implemented this into my codebase and you need to wrap them in double braces.

Which I personally don't mind since it further distinguishes multiple media-query inclusions from singles.

I've updated my code example to reflect this.

@ericrovtar
Copy link
Author

Clever. Thanks, guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants