Alex Rivera | Logout

Border around 100% body height and width (HTML 4.01 Strict)

Asked 2009-05-20T08:25:31.280
22

Okay, this is driving me crazy right now.

I want to have a border around my document. It should be nicely going around the whole window/viewport. So I define:

body {
  border: 1px solid red;
}

When my document is in quirks mode, this works fine. At least in IE, which is my primary target here. A red border shows up at the very edges of my page, obviously because by predefined CSS body and html are set to fill the screen.

When going to standards mode by setting a HTML 4.01 strict DOCTYPE, body and html collapse to the real (smaller) size of the content, the border is drawn right through the middle of the screen. So I define:

body, html {
  padding: 0px;
  margin: 0px;
  border: 0px none;
  width: 100%;
  height: 100%;
}

body {
  border: 1px solid red;
}

And I get — scroll bars, scrolling exactly one pixel to show the bottom/right borders. However, I want that border visible right away.

Is there a no-bullshit (like "height: 99.9%;", "overflow: hidden;" or "switch back to quirks mode") method to get a border at 100%, without unnecessary scroll bars? IE-only is fine, cross-browser would be better, of course.

Edit
Report

1 Answer

1

It also a bit ugly, but giving the body

position:relative;
top:-1px;
left:-1px;

worked for me.

answered 2010-07-29T08:19:21.060

Your Answer