Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a variable as !important with LESS?

Tags:

css

less

Is it possible to have a variable declared as !important with LESS? Currently, I am getting a syntax error with the following.

For example:

@fontColor: #000000 !important;

p {
    color: @fontColor;
}

Should render as:

p {
    color: #000000 !important;
}

I know there is a way of escaping that is mentioned HERE, using the following:

@fontColor: #000000 ~'!important';

There was talk about implementing it as simple syntax quite a while ago like my first example, just not to sure if they ever did - https://github.com/less/less.js/issues/1401

Using Visual Studio 2013 (Update 4)

like image 741
Fizzix Avatar asked Dec 25 '22 02:12

Fizzix


1 Answers

The accepted answer didn't work for me (I guess it was due to version, maybe).

What worked was the workaround mentioned in OP's question itself, which I didn't see at first.

In case it happens to someone else, just try the following:

// !important doesn't work
@fontColor: #000000 !important;

// !important works!
@fontColor: #000000 ~'!important';

Source

like image 127
falsarella Avatar answered Jan 17 '23 19:01

falsarella