- 語言特性
- Less - 巢狀規則
- Less - 巢狀指令和冒泡
- Less - 操作
- Less - 轉義
- Less - 函式
- Less - 名稱空間和訪問器
- Less - 作用域
- Less - 註釋
- Less - 匯入
- Less - 變數
- Less - 擴充套件
- Less - 混合(Mixin)
- Less - 引數化混合(Mixin)
- Less - 混合(Mixin)作為函式
- Less - 向混合(Mixin)傳遞規則集
- Less - 匯入指令
- Less - 匯入選項
- Less - 混合(Mixin)保護
- Less - CSS 保護
- Less - 迴圈
- Less - 合併
- Less - 父選擇器
- 函式
- Less - 雜項函式
- Less - 字串函式
- Less - 列表函式
- Less - 數學函式
- Less - 型別函式
- Less - 顏色定義函式
- Less - 顏色通道函式
- Less - 顏色操作
- Less - 顏色混合函式
- 用法
- Less - 命令列用法
- 在瀏覽器中使用 Less
- Less - 瀏覽器支援
- Less - 外掛
- Less - 程式化用法
- Less - 線上編譯器
- Less - 圖形介面
- Less - 編輯器和外掛
- Less - 第三方編譯器
- Less - 框架
- Less 有用資源
- Less - 快速指南
- Less - 有用資源
- Less - 討論
LESS - !important 關鍵字
描述
!important 關鍵字用於覆蓋特定的屬性。當它放在混合(Mixin)呼叫之後時,它會將所有繼承的屬性標記為!important。
以下示例演示了在 LESS 檔案中使用!important 關鍵字:
<html>
<head>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
<title>The !important keyword</title>
</head>
<body>
<h1>Welcome to Tutorialspoint</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>
接下來,建立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_mixins.htm
廣告