-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrem.less
More file actions
32 lines (28 loc) · 938 Bytes
/
rem.less
File metadata and controls
32 lines (28 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// rem + @media 适配不同尺寸的移动端设备
// 注意:less 4.0+ 除法不加括号不会被计算
// 常见设备的像素宽度
@deviceWidths: 320px, 360px, 375px, 400px, 414px, 480px, 750px;
.html-font-size(@design-font-size, @design-width) {
html {
font-size: @design-font-size;
}
each(@deviceWidths, {
@deviceWidth: @value; // 返回列表指定位置的值(起始位置 1)
@font-size-value: (@deviceWidth / @design-width * @design-font-size);
@font-size: round(@font-size-value, 2);
@media only screen and (min-width: @deviceWidth) {
html {
font-size: @font-size;
}
}
})
}
// px 转 rem
.px2rem(@name, @px, @design-font-size) {
@{name}: 1rem * round((@px / @design-font-size), 2);
}
@design-font-size: 16px;
.px2rem(@name, @px) {
.px2rem(@name, @px, @design-font-size);
}
.html-font-size(16px, 375px);