LESS
less是一门向后兼容的css语法扩展语言
变量
1 声明
以‘@’来声明
styles.less
// css样式
@WIDTH: 100px;
@HEIGHT: @WIDTH + 10px;
@FontSize: 12px;
@LetterSpacing: @FontSize * 1.38;
// 选择器
@circelSelector: circel;
.@{circelSelector} {
border-radius: 50%;
}
@pointerSelector: pointer;
.@{pointerSelector} {
cursor: pointer;
}
// 路径
@images: '../../assets/images/';
dome.less
// 文件名
@file: "../../";
@import '@{file}styles.less';
// 颜色定义
@font-color: pink;
@dark-font-color: darken(@font-color, 15%);
p {
height: @HEIGHT;
font-size: @FontSize * 3;
color: @font-color;
transition: color .50s ease-in;
letter-spacing: @LetterSpacing * 3;
}
p:hover{
color: @dark-font-color;
transition: color .50s ease-in;
}
.header{
@width: 500px;
width: @width;
height: @width;
background: url("@{images}h_f.jpg") no-repeat left top/cover;
}
Mixins
.bgImg() {
background-position: left top;
background-repeat: no-repeat;
background-size: cover;
}
.border-radius(@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
.square(@width, @height) {
width: @width;
height: @height;
}
.box-shadow(@x: 0; @y: 0; @blur: 1px; @color: #000) {
-webkit-box-shadow: @arguments;
-moz-box-shadow: @arguments;
box-shadow: @arguments;
}