Home > Blockchain >  How can I add vw to the hight with jQuery?
How can I add vw to the hight with jQuery?

Time:10-21

I want to do something like the below. Get the .content height and then add that height plus 27vw to .container height.

Is this at all possible?

let imageHeight = $('.content').height();
$('.container').css('height', imageHeight - '27vw');

CodePudding user response:

You can use the calc CSS function to add 27vw to the element's height:

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>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related