LESS 函数
LESS 函数
LESS映射JavaScript代码配合值,并使用预先定义的函数在样式表处理HTML元素方面。它提供了多种函数来操作的颜色,如round函数,floor函数,ceil函数,百分比等函数.
示例
<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); }
编译less文件
lessc style.less style.css
得到css文件
style.css .mycolor { color: #FF8000; width: 100%; }
输出
让我们来执行以下步骤,看看上面的代码工作:
保存上面的html代码到 functions.html 文件。
在浏览器中打开该HTML文件,得到如下输出显示。