简体   繁体   English

CSS 100%高度,绝对定位顶部0底部0

[英]CSS 100% height with absolute positioning top 0 bottom 0

I recently found a site that used a div with position absolute, and the top, left, right and bottom values all set to 0. This created a 100% high, 100% wide div. 我最近发现一个网站使用了一个绝对位置的div,并且top,left,right和bottom值都设置为0.这创建了一个100%高,100%宽的div。 I am now using this as well, and was wondering if there is any reason not to? 我现在也在使用它,并且想知道是否有任何理由不这样做?

It works really well, it's a simple solution, and the other way I was using had a bug I couldn't fix. 它工作得很好,这是一个简单的解决方案,而我使用的另一种方式有一个我无法解决的错误。 The application I'm using this for should only every take up the browser window, and never needs to be bigger. 我正在使用它的应用程序应该只占用浏览器窗口,并且永远不需要更大。

I am now using this as well, and was wondering if there is any reason not to? 我现在也在使用它,并且想知道是否有任何理由不这样做?

This technique works fantastically in modern browsers - there is no reason not to use it. 这种技术在现代浏览器中非常有效 - 没有理由不使用它。

(unless you care about some really old browsers (IE5/6?), which don't support setting top and bottom or left and right on the same element) (除非你关心一些非常古老的浏览器(IE5 / 6?),它们不支持在同一元素上设置topbottomleft right

Here's an answer I wrote earlier today which uses a similar technique. 这是我今天早些时候写的一个使用类似技术的答案

No, that's fine. 不,那没关系。 Just make sure it doesn't glitch up on different browsers, depending on what you are doing. 确保它不会在不同的浏览器上出现问题,具体取决于您正在做什么。 May I recommend making a jsFiddle and testing it on BrowserLab ? 我可以建议制作一个jsFiddle并在BrowserLab上进行测试吗?

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

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