variables - Dynamic class names in LESS -
i have following bit of less code working
@iterations: 940; @iterations: 940; @col:2.0833333333333333333333333333333%; // helper class, never show in resulting css // called long index above 0 .loopingclass (@index) when (@index > -20) { // create actual css selector, example result in // .myclass_30, .myclass_28, .... , .myclass_1 (~".gs@{index}") { // resulting css width: (@index/20+1)*@col; } // next iteration .loopingclass(@index - 60); } // end loop when index 0 .loopingclass (-20) {} // "call" loopingclass first time highest value .loopingclass (@iterations); it outputs our grid system so:
.gs940 { width: 100%; } .gs880 { width: 93.75%; } .gs820 { width: 87.5%; } .gs760 { width: 81.25%; } .gs700 { width: 75%; } etc etc etc
now want math class names produce following classes
.gs220-700 .gs280-640 .gs340-580 .gs400-520 .gs460-460 .gs520-400 .gs580-340 .gs640-280 .gs700-220 etc etc etc
basically .(@index) - (920px minus @index)
but have no idea if possible.
i don't think you're far off. i've done create second variable inside mixin, called @index2. find '920px minus @index' value you're looking for:
@index2 = (920-@index); this appended class name:
(~".gs@{index}-@{index2}") { this complete loop:
.loopingclass (@index) when (@index > 160) { @index2 = (920-@index); // create actual css selector, example result in // .myclass_30, .myclass_28, .... , .myclass_1 (~".gs@{index}-@{index2}") { // resulting css width: (@index/20+1)*@col; } // next iteration .loopingclass(@index - 60); } // "call" loopingclass first time highest value .loopingclass (@iterations); in order set looking (gs220-700 gs700-220), change @iterations equal 700.
worth noting currently, create classes in reverse order of how specified them in question.
Comments
Post a Comment