我想做一些类似下面的事情。获取.content高度,然后将该高度加上27vw到.container height。
这有可能吗?
let imageHeight = $('.content').height();
$('.container').css('height', imageHeight - '27vw');
发布于 2021-10-19 18:27:57
您可以使用calc
CSS function将27vw
添加到元素的高度:
let imageHeight = $('.content').height();
$('.container').css('height', `calc(${imageHeight}px + 27vw)`);
.container{
background-color:grey;
}
.content{
height:1vw;
background-color:yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="content"></div>
<div class="container"></div>
https://stackoverflow.com/questions/69639617
复制