W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
默認(rèn)變量只有在尚未設(shè)置時(shí)才能設(shè)置變量。此功能不是必需的,因?yàn)樽兞靠梢院苋菀椎赝ㄟ^(guò)定義它們后覆蓋。
下面的例子演示了在LESS文件中使用默認(rèn)變量:
<html> <head> <link rel="stylesheet" href="style.css" type="text/css" /> <title>LESS Default Variables</title> </head> <body> <h1>Welcome to W3Cschool</h1> <p>LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p> </body> </html>
接下來(lái),創(chuàng)建文件style.less。
@import "//hgci.cn/less/lib.less"; // first declaration of @color @color: green; // this will override @color defined previously p{ color : @color; }
@color: blue;
您可以使用以下命令將style.less編譯為style.css:
lessc style.less style.css
接下來(lái)執(zhí)行上面的命令,它將自動(dòng)創(chuàng)建style.css文件用下面的代碼:
p { color: green; }
讓我們執(zhí)行以下步驟,看看上面的代碼如何工作:
將上面的html代碼保存在less_default_variables.html文件中。
在瀏覽器中打開(kāi)此HTML文件,將顯示如下輸出。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話(huà):173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: