更少的css混合,参数A作为参数B的默认值
我目前使用较少的CSS,并尝试创建一个mixin,模仿速记参数的默认CSS行为 在css中,您经常声明更少的css混合,参数A作为参数B的默认值,css,parameters,less,mixins,Css,Parameters,Less,Mixins,我目前使用较少的CSS,并尝试创建一个mixin,模仿速记参数的默认CSS行为 在css中,您经常声明 margin: 5px 5px 10px; 它读作 margin: 5px 5px 10px 5px; 我也试过用边界半径混合器 .border-radius (@topright: 5px, @bottomright: @topright, @bottomleft: @topright, @topleft: @bottomright) {} 如果仅使用一个参数调用,我希望它将第一个参
margin: 5px 5px 10px;
它读作
margin: 5px 5px 10px 5px;
我也试过用边界半径混合器
.border-radius (@topright: 5px, @bottomright: @topright, @bottomleft: @topright, @topleft: @bottomright) {}
如果仅使用一个参数调用,我希望它将第一个参数作为所有参数的默认值。如果我用2个参数调用它,它应该将第一个参数作为第三个参数的默认值,第二个参数作为第四个参数的默认值
有没有一种方法可以在较少的单独情况下实现此行为?正确的方法是只接收一个参数
.border-radius(@px) {
-webkit-border-radius: @px;
-moz-border-radius: @px;
border-radius: @px;
}
然后可以使用一个参数调用它:
.border-radius(5px);
或者和很多人在一起。这需要您将它们放入变量中,或转义:
@myradius: 5px 5px 10px;
.border-radius(@myradius);
或
我认为使用后一个版本是为了简洁。正确的方法是只接收一个参数
.border-radius(@px) {
-webkit-border-radius: @px;
-moz-border-radius: @px;
border-radius: @px;
}
然后可以使用一个参数调用它:
.border-radius(5px);
或者和很多人在一起。这需要您将它们放入变量中,或转义:
@myradius: 5px 5px 10px;
.border-radius(@myradius);
或
我认为为了简洁起见,使用后一个版本。我想我会像引导程序在链接中那样对它们进行转义,您提供了。这篇文章读得很好。非常感谢您的链接和回答!我想我会像你提供的链接中引导程序那样逃离它们。这篇文章读得很好。非常感谢您的链接和回答!