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

Media query bubbling and html class #1867

Closed
ChrisButterworth opened this issue Feb 11, 2014 · 7 comments
Closed

Media query bubbling and html class #1867

ChrisButterworth opened this issue Feb 11, 2014 · 7 comments

Comments

@ChrisButterworth
Copy link

Been trying to figure this out for a while but how would I get something like this to work:

header{
        background:blue;
        @media screen and (min-width:1200), html.lt-ie9 &{
                background:red;
        }
}

Trying to do it this way to target desktop and IE versions below IE9; any help would be brilliant, otherwise I'd end up repeating myself over and over to get something done.

@seven-phases-max
Copy link
Member

header {
    background: blue;

    .desktop-and-old-ie() {
        background: red;
    }

    @media screen and (min-width: 1200) {.desktop-and-old-ie}
    html.lt-ie9 &                       {.desktop-and-old-ie}
}

In short, selectors and media queries can't be combined together since they are very different beasts, so mixins are your friends...

@ChrisButterworth
Copy link
Author

That's great, thanks.

Do you think it'd be a feature added in the future? It solves the problem now but I can see cases where there would be hundreds of mixins...

@lukeapage
Copy link
Member

Yes!

How about this...

This is using a feature that should be merged into master and released in 1.7 in the next couple of weeks.

.desktop-and-old-ie(@rules) {
      @media screen and (min-width: 1200) { @rules(); }
      html.lt-ie9 &                       { @rules(); }
}

header {
    background: blue;

    .desktop-and-old-ie({
        background: red;
    });
}

@lukeapage
Copy link
Member

So the .desktop-and-old-ie mixin describes the wrap and then you use that to abstract out the fact it is both a media query and a class.

@lukeapage
Copy link
Member

@seven-phases-max
Copy link
Member

Btw., nice #1859 example. I did not notice that this use-case is exactly what #965 started with :)

@ChrisButterworth
Copy link
Author

That's great, and a great example, thanks a lot.

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