开发者

How to set a div hight to a certain percent of a window height using jQuery?

开发者 https://www.devze.com 2023-03-04 00:21 出处:网络
A ra开发者_如何学JAVAther basic question, I guess, but I want help with it. I need to set up the height of div to 70% of the height of the browser window, and I want to do it with jQuery.

A ra开发者_如何学JAVAther basic question, I guess, but I want help with it.

I need to set up the height of div to 70% of the height of the browser window, and I want to do it with jQuery.

What's the best code for that?

Thank you for your help!

Dimitri Vorontzov


$('#theDiv').height(function(){
   return $(window).height() * 0.7;
});


Via Viewport-percentage lengths:

 height:70vh;

Jsfiddle: https://jsfiddle.net/Lztggxpk/1/

For more: https://developer.mozilla.org/en/docs/Web/CSS/length#Viewport-percentage_lengths

0

精彩评论

暂无评论...
验证码 换一张
取 消