- 語言特性
- LESS - 巢狀規則
- LESS - 巢狀指令和冒泡
- LESS - 運算
- LESS - 轉義
- LESS - 函式
- LESS - 名稱空間和訪問器
- LESS - 作用域
- LESS - 註釋
- LESS - 匯入
- LESS - 變數
- LESS - 擴充套件
- LESS - 混合宏
- LESS - 引數化混合宏
- LESS - 混合宏作為函式
- LESS - 向混合宏傳遞規則集
- LESS - 匯入指令
- LESS - 匯入選項
- LESS - 混合宏保護
- LESS - CSS 保護
- LESS - 迴圈
- LESS - 合併
- LESS - 父選擇器
- 函式
- LESS - 雜項函式
- LESS - 字串函式
- LESS - 列表函式
- LESS - 數學函式
- LESS - 型別函式
- LESS - 顏色定義函式
- LESS - 顏色通道函式
- LESS - 顏色運算
- LESS - 顏色混合函式
- 用法
- LESS - 命令列用法
- 在瀏覽器中使用 LESS
- LESS - 瀏覽器支援
- LESS - 外掛
- LESS - 程式化用法
- LESS - 線上編譯器
- LESS - GUI
- LESS - 編輯器和外掛
- LESS - 第三方編譯器
- LESS - 框架
- LESS 有用資源
- LESS - 快速指南
- LESS - 有用資源
- LESS - 討論
LESS - CSS 保護
描述
保護用於匹配表示式上的簡單值或多個引數。它應用於 CSS 選擇器。它是宣告混合宏並立即呼叫的語法。為了成功實現if型別語句;將其與特性&結合使用,允許你組合多個保護。
示例
以下示例演示了在 LESS 檔案中使用css保護:
css_guard.htm
<!doctype html>
<head>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
</head>
<body>
<div class = "cont">
<h2>Welcome to TutorialsPoint</h2>
</div>
<div class = "style">
<h3>The largest Tutorials Library on the web.</h3>
</div>
</body>
</html>
接下來,建立style.less檔案。
style.less
@usedScope: global;
.mixin() {
@usedScope: mixin;
.cont when (@usedScope = global) {
background-color: red;
color: black;
}
.style when (@usedScope = mixin) {
background-color: blue;
color: white;
}
@usedScope: mixin;
}
.mixin();
您可以使用以下命令將style.less檔案編譯為style.css:
lessc style.less style.css
執行上述命令;它將自動建立包含以下程式碼的style.css檔案:
style.css
.style {
background-color: blue;
color: white;
}
輸出
按照以下步驟檢視上述程式碼的工作原理:
將上述 html 程式碼儲存到css_guard.htm檔案中。
在瀏覽器中開啟此 HTML 檔案,將顯示以下輸出。
廣告