简体   繁体   English

如何在页面加载后使DIV填满整个屏幕

[英]How to make a DIV fill the whole screen after page loading

We are making a website for the TEDx in our city and we're stuck.. 我们正在为我们城市的TEDx建立一个网站,我们被困住了..

Here's a draft copy of it: tedx.mozerov.ru 这是它的草稿副本:tedx.mozerov.ru

We have a div id="section-event" which we want to be for the whole page on loading. 我们有一个div id =“section-event”,我们希望在加载时整个页面。 We added the height:100%; 我们增加了高度:100%; and width:100%;, but the block is still does not fill the whole page :( 和宽度:100%;,但块仍然没有填满整个页面:(

Please help! 请帮忙!

好吧,不知道你将如何使用这个div,但是:

position: absolute; top: 0; left: 0; height: 100%; width: 100%;

Apply height:100% to both the html and body elements. 将高度:100%应用于html和body元素。 I just tested in FireBug and I think it achieves the effect you want. 我刚刚在FireBug中测试过,我认为它可以实现您想要的效果。

I still cannot comment on other people's answers so here is my answer and it's only a simple addition to uotonyh's that may work. 我仍然无法评论其他人的答案,所以这是我的答案,这只是对uotonyh的一个简单的补充,可能有用。

Make the position absolute and add an arbitrary z-index. 使位置绝对并添加任意z-index。 As long as the z-index is higher than the other absolute/relative DIVs, then it should take up the entire viewport. 只要z-index高于其他绝对/相对DIV,它就应占用整个视口。 If you see a space on the top and left side, then add margin: 0px; 如果你在顶部和左侧看到一个空格,那么添加margin:0px; to your body css tag. 到你的身体css标签。

Ex. 防爆。

#section-event {
    position: absolute;
    height: 100%;
    width: 100%;
    z-index: 99;
}

It depends on your website layout, sometimes you have incompatibilities. 这取决于您的网站布局,有时您有不兼容性。 But in general something like this works: 但总的来说这样的工作:

http://jsfiddle.net/8Pvtk/ http://jsfiddle.net/8Pvtk/

#redoverlay {
    background-color: red;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

I've seen this being used in some sites where the <div id="redoverlay"></div> element exists at all times, but is with its visibility disabled. 我已经看到这在某些网站中使用,其中<div id="redoverlay"></div>元素始终存在,但其可见性已被禁用。 When its needed its set to visible by JavaScript. 当它需要通过JavaScript显示它的设置时。

What you probably need is margin: 0px in body 你可能需要的是margin: 0pxbody

http://jsfiddle.net/pVNhU/ http://jsfiddle.net/pVNhU/

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

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