import語句可以具有保存路徑的變量。當(dāng)你引用一個普通的父目錄時,這是非常有用的。
下面的示例演示了在import語句中使用變量:
<html> <head> <link rel="stylesheet" href="style.css" type="text/css" /> <title>LESS Variables in Import Statements</title> </head> <body> <div class="myclass"> <h2>Welcome to W3Cschool</h2> <p>LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p> </div> </body> </html>
接下來,創(chuàng)建文件style.less。
@path : "http://www.15014759268.cn/less"; @import "@{path}/external1.less"; .myclass{ color : #A52A2A; }
.myclass{ background: #C0C0C0; }
您可以使用以下命令將style.less編譯為style.css:
lessc style.less style.css
接下來執(zhí)行上面的命令,它將自動創(chuàng)建style.css文件用下面的代碼:
.myclass { background: #C0C0C0; } .myclass { color: #A52A2A; }
讓我們執(zhí)行以下步驟,看看上面的代碼如何工作:
將上面的html代碼保存在less_variables_interpolation_import.html文件中。
在瀏覽器中打開此HTML文件,將顯示如下輸出。
更多建議: