- 語言特性
- 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 - 圖形使用者介面
- LESS - 編輯器和外掛
- LESS - 第三方編譯器
- LESS - 框架
- LESS 有用資源
- LESS - 快速指南
- LESS - 有用資源
- LESS - 討論
LESS - 函式
描述
LESS 將 JavaScript 程式碼與值的處理對映起來,並使用預定義函式來處理樣式表中 HTML 元素的各個方面。它提供了一些用於處理顏色的函式,例如 round 函式、floor 函式、ceil 函式、percentage 函式等。
示例
以下示例演示了在 LESS 檔案中使用函式:
<html>
<head>
<title>Less Functions</title>
<link rel = "stylesheet" type = "text/css" href = "style.css" />
</head>
<body>
<h1>Example using Functions</h1>
<p class = "mycolor">LESS enables customizable,
manageable and reusable style sheet for web site.</p>
</body>
</html>
現在建立 *style.less* 檔案。
style.less
@color: #FF8000;
@width:1.0;
.mycolor {
color: @color;
width: percentage(@width);
}
您可以使用以下命令將 *style.less* 檔案編譯為 *style.css*:
lessc style.less style.css
現在執行上述命令;它將自動建立包含以下程式碼的 *style.css* 檔案:
style.css
.mycolor {
color: #FF8000;
width: 100%;
}
輸出
按照以下步驟檢視上述程式碼的工作原理:
將上述 html 程式碼儲存到 **functions.html** 檔案中。
在瀏覽器中開啟此 HTML 檔案,您將看到以下輸出。
廣告