Use border-width like parameter in LESS

烂漫一生 提交于 2019-12-13 04:29:33

问题


I'm still discovering the utility of this technology. Please I have a question if someone can answer me. I'm trying to create a function like:

.advancedBorder( @color, @size )
{
     border: @size solid @color;
}

div
{
    .advancedBorder( #FFF, 1px 0px 1px 0px);
}

So, I tried in many ways to make it possible but without any success.

The real reason is to create a function that can be added to any box and setting for it any border size and color I prefer with minimum lines of code. Can someone show me how can be done?

Thanks!


回答1:


The syntax generated is not valid in CSS. You are passing in the following:

@color = #FFF @size = 1px 0px 1px 0px

which in your mixin will generate:

border: 1px 0px 1px 0px solid #FFF;

as CSS. This is not a valid shorthand for borders in CSS. You need something like:

.advancedBorder( @color, @size ){
    border-width: @size;
    border-color: @color;
    border-style: solid;
}


来源:https://stackoverflow.com/questions/18016504/use-border-width-like-parameter-in-less

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