简体   繁体   English

可以使用javascript将div高度更改为100%减去100px?

[英]possible to change div height to 100% minus 100px with javascript?

I know almost nothing about JS so I just thought I would ask. 我对JS几乎一无所知,所以我想问一下。 I saw this in another thread: 我在另一个线程中看到了这一点:

<script type="text/javascript">
function contentSize()
{
    document.getElementById('content').style.height=(window.availHeight-40)+"px";
}
onload=contentSize;
onresize=contentSize;
<script>

Looks straight forward but doesn't work... 看起来直截了当,但不起作用...

If you do use jQuery, then http://api.jquery.com/height/ 如果您确实使用jQuery,则http://api.jquery.com/height/

IE supplies this info differently than Chrome/FF/Safari so probably better if you do use the lib to help cover all the bases. IE浏览器不是Chrome / FF / Safari浏览器这样可能会更好,如果使用的lib帮助涵盖所有的基础不同提供这些信息。 You can use the height() function both to get the size of the window and set the height of your target content. 您可以使用height()函数来获取窗口的大小并设置目标内容的高度。

$('#mydiv').height( $(window).height() - 100 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM