Search code examples
lessmixins

Lesscss one level up mixing


pretty sure this isn't at all possible but ...

Say I have this mixin:

.horizontalList() {
    background:blue;
        & li {
            display:inline-block;
        }
}

The css it generates is:

.something{
    background:blue;
}

.something li{
    display:inline-block;
}

Is it possible to generate the following CSS using a similar mixin?

.something{
    background:blue;
}

.something li{
    display:inline-block;
}

.ie6 .something li,
.ie7 .something li
{
    display:inline;
}

... So the ie6 and ie7 stuff is before the selector and I can make use of the Paul Irish conditional comments idea

I know that I could add a css hack to do the old IE stuff but I prefer not to have these in my stylesheet.

Thanks!!!


Solution

  • You need to do it in the mixin:

    LESS

    .horizontalList() {
        background:blue;
            & li {
                display:inline-block;
            }
            .ie6 & li,
            .ie7 & li {
                display: inline;
            }
    }
    

    Call It

    .something {
      .horizontalList;
    }
    

    CSS Output

    .something {
      background: blue;
    }
    .something li {
      display: inline-block;
    }
    .ie6 .something li,
    .ie7 .something li {
      display: inline;
    }