简体   繁体   中英

In less css is there a way to pass in a selected elments id or class into a mixin?

.w(@w, @h){
    width: (@widget-w * @w) + (@widget_margin_right * @w);
    height: (@widget-h * @h) + (@widget_margin_bottom * @h);
} 
[class*='w_']{
    .w(1,1);
}

So in this I have html elements with a class that determines the width and height of the element. Like so.... And this div is going to be @widget-w = 228px; @widget-h = 194px;

Now I had it like this .w_1x1{ .w(1,1); } .w_2x1{ .w(2,1); } But I'd like it more automated to fit for any size i want at any time So i'm trying to make a mixin that i can pass into the class name to simplify it.

I believe you would have to do that with javascript/jquery. LESS is great for calculations, but it's compiled BEFORE the page is laid out.

In other words, it would not be able to dynamically pull the height or width unless it ran the compiled CSS after the page had already rendered and been styled.

So that is a no.


Some extra info:

LESS is a CSS preprocessor, which means it is designed to process before the browser loads anything on the page. Hopefully, you're using a compiler to compile your LESS into CSS, and not compiling client side (which is not recommended).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM