Skip to content

Media query bubbling and html class #1867

Closed

Description

@ChrisButterworth

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.

Activity

  1. seven-phases-max commented on Feb 11, 2014

    @seven-phases-max
    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...

  2. ChrisButterworth commented on Feb 11, 2014

    @ChrisButterworth
    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...

  3. lukeapage commented on Feb 11, 2014

    @lukeapage
    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;
        });
    }
    
  4. lukeapage commented on Feb 11, 2014

    @lukeapage
    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.

  5. seven-phases-max commented on Feb 12, 2014

    @seven-phases-max
    Member

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

  6. ChrisButterworth commented on Feb 12, 2014

    @ChrisButterworth
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions