一、问题
在 scss 中使用 calc 计算变量的时候,没有产生任何效果,在开发这工具中可以看到并没有解析这段代码。
$topHeight: 6.41rem;
$leftWidth: 20.67rem;
.home {
width: 100%;
height: 100%;
position: relative;
&-top {
position: absolute;
top: 0;
position: absolute;
z-index: 1;
width: 100%;
height: $topHeight;
}
&-left {
position: absolute;
top: $topHeight;
left: 0;
z-index: 1;
width: $leftWidth;
height: calc(100% - $topHeight);
}
}
二、解决方法
在 calc 中通过 #{变量}
这种方式使用即可。
$topHeight: 6.41rem;
$leftWidth: 20.67rem;
.home {
width: 100%;
height: 100%;
position: relative;
&-top {
position: absolute;
top: 0;
position: absolute;
z-index: 1;
width: 100%;
height: $topHeight;
}
&-left {
position: absolute;
top: $topHeight;
left: 0;
z-index: 1;
width: $leftWidth;
height: calc(100% - #{$topHeight});
}
}