有一个common.less文件:
// 根据媒体查询,设置不同屏幕中的html字号
// 屏幕划分为15等份
// 默认显示html字号参考750px的宽度
@no: 15;
html {
font-size: 50px;
}
//320px
@media screen and (min-width: 320px) {
html {
font-size: (320px / @no);
}
}
我想在 index.less 文件中引入刚才的less文件, 可以通过导入式实现:
// 首页css样式
// 在index.less中导入common.less文件
@import "common";
这时查看index.css, 可以看到已经被编译好了:
html {
font-size: 50px;
}
@media screen and (min-width: 320px) {
html {
font-size: 21.33333333px;
}
}