16

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. 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.

Brandon
  • 16,382
  • 12
  • 55
  • 88
  • 1
    I think there are some issues with `position: absolute;` on mobile devices (certainly iPhone, from my own browsing experiences). But I'm not entirely sure if there's any real reason against it. So long as you deal with the `overflow`s properly. – David Thomas Feb 21 '11 at 19:18
  • Looks like Twitter Bootstrap is using the same technique in the Carousel as well setting top and bottom to 0 for the left and right carousel-controls. – firedrawndagger Apr 21 '14 at 00:24

2 Answers2

20

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)

Here's an answer I wrote earlier today which uses a similar technique.

Community
  • 1
  • 1
thirtydot
  • 224,678
  • 48
  • 389
  • 349
5

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?

0x60
  • 1,096
  • 4
  • 14
  • 23