鍍金池/ 教程/ HTML/ Less !important關(guān)鍵字
Less混合作用域
Less轉(zhuǎn)義
Less使用擴(kuò)展精確匹配
Less URLs
Less作用域
Less變量名
Less命名參數(shù)
Less導(dǎo)入選項(xiàng)reference關(guān)鍵詞
Less變量插值屬性
Less變量延遲加載
Less合并風(fēng)格及高級(jí)混入
Less模式匹配
Less !important關(guān)鍵字
Less教程
Less守護(hù)命名空間
Less nth表達(dá)式
Less經(jīng)典用例
Less變量插值
Less擴(kuò)展內(nèi)部規(guī)則集
Less擴(kuò)展附加到選擇器
Less缺省變量
Less函數(shù)
Less高級(jí)參數(shù)和@rest變量
Less混合在另一個(gè)混合中
Less混合類型
Less導(dǎo)入指令
Less @arguments變量
Less擴(kuò)展all
Less擴(kuò)展
Less重復(fù)檢測(cè)
Less導(dǎo)入
Less選擇器插值擴(kuò)展
Less運(yùn)算符
Less Mixins使用多參數(shù)
Less嵌套規(guī)則
Less參數(shù)化混合
Less安裝
Less命名空間和訪問器
Less變量概述
Less混合作為參數(shù)
Less import語句
Less在混合類型的選擇器
Less注釋
Less作用域及擴(kuò)展@media
Less選擇器
Less混合命名空間
Less不輸出混合類型
Less Mixin和返回值
Less變量
Less擴(kuò)展嵌套選擇器
Less傳遞規(guī)則集到混合
Less導(dǎo)入選項(xiàng)inline關(guān)鍵詞

Less !important關(guān)鍵字

!important 關(guān)鍵字是用來覆蓋指定的屬性。當(dāng)它被放置的 mixin 調(diào)用后,它標(biāo)志著所有繼承屬性為 !important。
下面的例子演示了LESS文件使用 !important 關(guān)鍵字。
<html>
<head>
  <link rel="stylesheet" href="style.css" type="text/css" />
  <title>The !important keyword</title>
</head>
<body>
<h1>Welcome to Yiibai Yiibai</h1>
<p class="para1">LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p>
<p class="para2">LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p>
</body>
</html>
接下來,創(chuàng)建文件 style.less。

style.less

.mixin(){
  color: #900;
  background: #F7BE81;
}
.para1{
  .mixin();
}
.para2{
  .mixin() !important;
}
你可以編譯 style.less 使用下面的命令來生成 style.css 文件:
lessc style.less style.css
接著執(zhí)行上面的命令,它會(huì)自動(dòng)創(chuàng)建 style.css 文件,下面的代碼:

style.css

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

輸出結(jié)果

讓我們來執(zhí)行以下步驟,看看上面的代碼工作:
  • 保存上面的HTML代碼在 less_mixin_important.html 文件。
  • 在瀏覽器中打開該HTML文件,得到如下輸出顯示。