有时我希望我可以只更改媒体查询中的一个变量,然后
HTML:
<div id="wrap">
<div class="child1"></div>
<div class="child2"></div>
</div>
少(不起作用):
@base: 1000px;
@media all and (max-width: 768px) {
@base: 600px;
}
.child1 {
// 500px normally, 300px on small screens
height: 0.5 * @base;
}
.child2 {
// 250px normally, 150px on small screens
height: 0.25 * @base;
}
这当然行不通,因为在编译时,@base
已设置并应用于所有类。但是,我遇到了这种肮脏的解决方法:
较少的:
#wrap
{
font-size: 1000px;
@media all and (max-width: 768px) {
font-size: 600px;
}
.child1 {
// 500px normally, 300px on small screens
height: 0.5em;
}
.child2 {
// 250px normally, 150px on small screens
height: 0.25em;
}
}
假设我的元素中实际上没有任何文本(或者文本仅出现在叶节点中并明确设置它们的字体大小),使用这种方法是否有任何严重的缺点?