How to read this LESS css?

倖福魔咒の 提交于 2019-12-01 10:45:09

@1cols etc are just variable names. Variable names in less are allowed to start with numbers.

@1col: @1cols;

That's just making the saying that variable @1col equals the variable @1cols set earlier. Presumably, "1col" because 1 is singular, but the others are plural, so it just gives you the option of using either @1col or @1cols both of them being the same value.

@1cols: ( 1 * (@column + @gutter) - @gutter) / @em;

That's just math. If you want a section that's 3 columns width, that's 3 times the (column width + gutter width) minus one gutter.

.width (@cols:1) {
width: (@cols * (@column + @gutter) - @gutter) / @em;
}

That's a mixin function that takes a variable number of columns with a default parameter of 1. You can use it like this:

.my-class{
   .width(3);
}
/* these two are identical */
.my-class{
   width: @3cols;
}

The benefit of the first method is that you can replace 3 with a variable so you can use it elsewhere.

@ is a variable identifier... similar to $ in php.

So what hes doing is defining a mixin which is in some respects like a function, that takes the argument @cols with a default value of 1 if none is provided. this mixin then sets the width css property to the value of the expression:

(@cols * (@column + @gutter) - @gutter) / @em;

Your @em value is going to be the value of 1em in pixels i think. So if your base font-size is 12 then @em = 12.

As far as the @1col: @1cols; thats just a convenience so that you can use @1col (singular) or @1cols (plural) and they mean the same thing.

The other answers nicely explain what LESS files do, so I'll talk about his use of @em.

If you do

.some_class { 
    just_an_em: @em 
}

in your .less file, it will come out to

.come_class {
    just_an_em: 16em
}

in .css after compiling. This seems to be because LESS preserves units upon division so that '16/@em' gives '1em', as expected.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!