LESS 减小css文件大小
LESS 减小css文件大小
扩展有助于减少生成的CSS代码。
例子
<!--extend_syntax.htm--> <!doctype html> <head> <link rel = "stylesheet" href = "style.css" type = "text/css" /> </head> <body> <div class = "cont"> <div class = "style"> <h2 class = "cont">The largest Tutorials Library on the web.</h2> <ul> <li>HTML</li> <li>SASS</li> <li>LESS</li> </ul> </div> </div> </body> </html>
接下来创建style.less文件
/*style.less*/ .style { display: inline-block; background-color: black; color: white; } .cont { &:extend(.style); } .nav { &:extend(.style); }
使用下面命令编译less文件
lessc style.less style.css
得到css文件
/*style.css*/ .style, .cont, .nav { display: inline-block; background-color: black; color: white; }
输出
执行以下步骤:
保存上面的html代码到extend_syntax.htm.html文件。
在浏览器中打开该HTML文件,输出如下得到显示。