
- 語言特性
- 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 - GUI
- Less - 編輯器和外掛
- Less - 第三方編譯器
- Less - 框架
- Less 有用資源
- Less - 快速指南
- Less - 有用資源
- Less - 討論
LESS - 安裝
在本節中,我們將逐步瞭解如何安裝 LESS。
LESS 的系統要求
作業系統 - 跨平臺
瀏覽器支援 - IE(Internet Explorer 8+)、Firefox、Google Chrome、Safari。
LESS 的安裝
現在讓我們瞭解 LESS 的安裝過程。
步驟 1 - 我們需要 NodeJs 來執行 LESS 示例。要下載 NodeJs,請開啟連結 https://nodejs.org/en/,您將看到如下所示的螢幕 -

下載最新功能版本的 zip 檔案。
步驟 2 - 執行安裝程式以在您的系統上安裝Node.js。
步驟 3 - 接下來,透過 NPM(Node 包管理器)在伺服器上安裝 LESS。在命令提示符中執行以下命令。
npm install -g less
步驟 4 - 成功安裝 LESS 後,您將在命令提示符中看到以下行 -
`-- less@2.6.1 +-- errno@0.1.4 | `-- prr@0.0.0 +-- graceful-fs@4.1.3 +-- image-size@0.4.0 +-- mime@1.3.4 +-- mkdirp@0.5.1 | `-- minimist@0.0.8 +-- promise@7.1.1 | `-- asap@2.0.3 +-- request@2.69.0 | +-- aws-sign2@0.6.0 | +-- aws4@1.3.2 | | `-- lru-cache@4.0.0 | | +-- pseudomap@1.0.2 | | `-- yallist@2.0.0 | +-- bl@1.0.3 | | `-- readable-stream@2.0.6 | | +-- core-util-is@1.0.2 | | +-- inherits@2.0.1 | | +-- isarray@1.0.0 | | +-- process-nextick-args@1.0.6 | | +-- string_decoder@0.10.31 | | `-- util-deprecate@1.0.2 | +-- caseless@0.11.0 | +-- combined-stream@1.0.5 | | `-- delayed-stream@1.0.0 | +-- extend@3.0.0 | +-- forever-agent@0.6.1 | +-- form-data@1.0.0-rc4 | | `-- async@1.5.2 | +-- har-validator@2.0.6 | | +-- chalk@1.1.1 | | | +-- ansi-styles@2.2.0 | | | | `-- color-convert@1.0.0 | | | +-- escape-string-regexp@1.0.5 | | | +-- has-ansi@2.0.0 | | | | `-- ansi-regex@2.0.0 | | | +-- strip-ansi@3.0.1 | | | `-- supports-color@2.0.0 | | +-- commander@2.9.0 | | | `-- graceful-readlink@1.0.1 | | +-- is-my-json-valid@2.13.1 | | | +-- generate-function@2.0.0 | | | +-- generate-object-property@1.2.0 | | | | `-- is-property@1.0.2 | | | +-- jsonpointer@2.0.0 | | | `-- xtend@4.0.1 | | `-- pinkie-promise@2.0.0 | | `-- pinkie@2.0.4 | +-- hawk@3.1.3 | | +-- boom@2.10.1 | | +-- cryptiles@2.0.5 | | +-- hoek@2.16.3 | | `-- sntp@1.0.9 | +-- http-signature@1.1.1 | | +-- assert-plus@0.2.0 | | +-- jsprim@1.2.2 | | | +-- extsprintf@1.0.2 | | | +-- json-schema@0.2.2 | | | `-- verror@1.3.6 | | `-- sshpk@1.7.4 | | +-- asn1@0.2.3 | | +-- dashdash@1.13.0 | | | `-- assert-plus@1.0.0 | | +-- ecc-jsbn@0.1.1 | | +-- jodid25519@1.0.2 | | +-- jsbn@0.1.0 | | `-- tweetnacl@0.14.1 | +-- is-typedarray@1.0.0 | +-- isstream@0.1.2 | +-- json-stringify-safe@5.0.1 | +-- mime-types@2.1.10 | | `-- mime-db@1.22.0 | +-- node-uuid@1.4.7 | +-- oauth-sign@0.8.1 | +-- qs@6.0.2 | +-- stringstream@0.0.5 | +-- tough-cookie@2.2.2 | `-- tunnel-agent@0.4.2 `-- source-map@0.5.3
示例
以下是一個簡單的 LESS 示例。
hello.htm
<!doctype html> <head> <link rel = "stylesheet" href = "style.css" type = "text/css" /> </head> <body> <h1>Welcome to TutorialsPoint</h1> <h3>Hello!!!!!</h3> </body> </html>
現在讓我們建立一個名為style.less的檔案,它與 CSS 非常相似,唯一的區別是它將以.less副檔名儲存。這兩個檔案,.html和.less都應建立在nodejs資料夾內。
style.less
@primarycolor: #FF7F50; @color:#800080; h1 { color: @primarycolor; } h3 { color: @color; }
使用以下命令將style.less檔案編譯為style.css -
lessc style.less style.css

當您執行上述命令時,它將自動建立style.css檔案。每當您更改 LESS 檔案時,都需要在cmd中執行上述命令,然後style.css檔案將更新。
當您執行上述命令時,style.css檔案將包含以下程式碼 -
style.css
h1 { color: #FF7F50; } h3 { color: #800080; }
輸出
現在讓我們執行以下步驟,看看上面程式碼是如何工作的 -
將上述 html 程式碼儲存在hello.htm檔案中。
在瀏覽器中開啟此 HTML 檔案,將顯示以下輸出。

廣告