Less !important關鍵字

!important 關鍵字是用來覆蓋指定的屬性。當它被放置的 mixin 調用後,它標誌着所有繼承屬性爲 !important。

下面的例子演示了LESS文件使用 !important 關鍵字。

The !important keyword

Welcome to Yiibai Yiibai

LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.

LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.

接下來,創建文件 style.less。

style.less

.mixin(){
color: #900;
background: #F7BE81;
}
.para1{
.mixin();
}
.para2{
.mixin() !important;
}

你可以編譯 style.less 使用下面的命令來生成 style.css 文件:

lessc style.less style.css

接着執行上面的命令,它會自動創建 style.css 文件,下面的代碼:

style.css

.para1 {
color: #900;
background: #F7BE81;
}
.para2 {
color: #900 !important;
background: #F7BE81 !important;
}

輸出結果

讓我們來執行以下步驟,看看上面的代碼工作:

  • 保存上面的HTML代碼在 less_mixin_important.html 文件。

  • 在瀏覽器中打開該HTML文件,得到如下輸出顯示。

Less