HTML blank I want to erase

2019-07-17 08:07发布

问题:

I have a new problem that bugs me ...

I am making a web page that I want to be fixed with no scrolling and most important I want my main Div to fill aaaaaaaaall my available space...

I made this code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <title>There is a @#!¤*-ing blank !</title>
    <style type='text/css'>
        html {margin:0px;padding:0px;height:100%;overflow:hidden;border: 3px solid green}
        div {margin:0px;padding:0px;}
    </style>
  </head>

<body onload="document.getElementById('mydiv').style.height=document.getElementsByTagName('html')[0].offsetHeight+'px'"><div id="mydiv" style="margin:0px;padding:0px;width:100%;border: 2px solid red"></div></body> </html>

As you can see I get a white space between my body element border and my div element border even though my body padding and div margin are set to 0...

I had once read "More Eric Meyer on CSS" that contains a solution to this issue but it was a long time ago and I don't remember ...

Any help would be greatly appreciated ^^.

回答1:

You didn't set the body's style:

body {margin: 0px; padding: 0px; height: 100%;}


回答2:

Your body margin isn't set to 0px, just that of html.



回答3:

Set the margin to 0 on the body tag.

body {margin:0;}


回答4:

In addition - rather than adding:

padding: 0; margin: 0;

to every selector do it globally at the top of your CSS file:

* { padding: 0; margin: 0; }