HTML blank I want to erase

断了今生、忘了曾经 提交于 2019-12-11 03:48:32

问题


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; }


来源:https://stackoverflow.com/questions/1058179/html-blank-i-want-to-erase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!