Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwrite less mixin

Tags:

css

mixins

less

I wish to remove border radius from all the elements in Bootstrap. So I created custom-mixins.less and placed following lines in it, hopping that it would overwrite the original .border-radius mixin but didn't.

// Border Radius
.border-radius(@radius) {      
}

So I tried following lines as an alternative which actually worked.

// Border Radius
.border-radius(@radius) {
  @radius : 0px;
  -webkit-border-radius: @radius;
     -moz-border-radius: @radius;
          border-radius: @radius;
}

I tried some mixins at http://less2css.org. It seems that less instead of overwriting the mixins, appends all the properties from later mixin to the original one. Is there any cleaner and easier solution to this????

like image 420
Asur Avatar asked Jun 14 '13 03:06

Asur


People also ask

What can be passed to a less mixin?

Mixins are a group of CSS properties that allow you to use properties of one class for another class and includes class name as its properties. In LESS, you can declare a mixin in the same way as CSS style using class or id selector. It can store multiple values and can be reused in the code whenever necessary.

Can a mixin override a method?

As seen before, one of the curious properties of mixins is that if they are “linked” to a class, they can override its methods.

What does the special variable @arguments do in a less mixin?

Additionally, LESS has a special variable named @arguments which will pass the default values all together.


1 Answers

Less works exactly like CSS does in this respect. For example, if you wrote this CSS:

p { border: 1px solid black; }

It would give all paragraphs a black border. If later in the document you added:

p { }

You wouldn't expect it to overwrite your previous definition, right?

So, in this case it's the expected behaviour, you need to specifically overwrite the CSS values you want to overwrite.

like image 69
nerdburn Avatar answered Sep 22 '22 15:09

nerdburn