[英]Setting HTML and BODY CSS using JS
In CSS, to set the height of a div so that it stretches from the top of the page to the bottom is done like so: 在CSS中,要设置div的高度,以使其从页面顶部延伸到底部,如下所示:
html, body, #xdiv {
height: 100%;
min-height: 100%;
}
The problem is, this executes straight away, so when the text or content loads, it's not 100% any more. 问题是,这会立即执行,因此在加载文本或内容时,它不再是100%了。 My question is, can I use Jquery or JS to set the above after page load?
我的问题是,能否在页面加载后使用Jquery或JS来设置以上内容?
You can use load
: 您可以使用
load
:
$(window).load(function() {
$('html, body, #xdiv').css({ "height": "100%", "min-height": "100%"});
});
Try This: http://jsfiddle.net/00ho9kgv/ 试试看: http : //jsfiddle.net/00ho9kgv/
To vertically-center content, you'll need to wrap and use display: table
, etc: http://jsfiddle.net/00ho9kgv/1/ 要使内容垂直居中,您需要包装并使用
display: table
等: http : //jsfiddle.net/00ho9kgv/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.