Use border-width like parameter in LESS

2019-09-09 17:50发布

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条回答
等我变得足够好
2楼-- · 2019-09-09 18:04

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;
}
查看更多
登录 后发表回答