How can I get rid of the gap at the edge of the page?

我是研究僧i 提交于 2021-02-05 04:59:36

问题


I already set the border, padding and margin to 0px for the body and two of my divs. But I still can't seem to get rid of the gap.

#body{
 padding: 0px ;
 border:0px ; 
margin:0px;
width:100%;
height:100vh;
}


#mainPage {
height:100vh;
width:100%;
background-color: #2469ff;
padding: 0px;
border:0px; 
margin:0px;
}

#navBar{

height:70px; 
width:100%;
Background-color: #1f1f1f;  
padding: 0px ;
border:0px ; 
margin:0px;
}

That's all my CSS so far.

Here is my HTML. It's very basic at the moment.

<html>  
     <head>    
     <title>
     Ice Arena
     </title>          
     </head>    
     <body>       
          <div id="mainPage">       
              <div id="navBar">      
              </div>  
              <div id="leftPanel">      
              </div>   
          </div>    
     </body>
</html>

As I said, I don't know why it's doing this. I'm sure I made a mistake, I'm still a beginner with CSS and HTML.


回答1:


Add the following CSS margin reset:

html,
body {
    margin: 0;
}

Snippet below:

html,
body {
  margin: 0;
}

#body {
  padding: 0px;
  border: 0px;
  margin: 0px;
  width: 100%;
  height: 100vh;
}

#mainPage {
  height: 100vh;
  width: 100%;
  background-color: #2469ff;
  padding: 0px;
  border: 0px;
  margin: 0px;
}

#navBar {
  height: 70px;
  width: 100%;
  Background-color: #1f1f1f;
  padding: 0px;
  border: 0px;
  margin: 0px;
}
<body>
  <div id="mainPage">
    <div id="navBar">
    </div>
    <div id="leftPanel">
    </div>
  </div>
</body>



回答2:


Use the following to remove the default margin from body:

html,
body {
  margin: 0;
}

I strongly suggest you read this:

Default CSS Values for HTML Elements

Default CSS Values for body [ display: block; margin: 8px;]

#body {
  padding: 0px;
  border: 0px;
  margin: 0px;
  width: 100%;
  height: 100vh;
}

#mainPage {
  height: 100vh;
  width: 100%;
  background-color: #2469ff;
  padding: 0px;
  border: 0px;
  margin: 0px;
}

#navBar {
  height: 70px;
  width: 100%;
  Background-color: #1f1f1f;
  padding: 0px;
  border: 0px;
  margin: 0px;
}

html,
body {
  margin: 0;
}
<html>

<head>
  <title>
    Ice Arena
  </title>
</head>

<body>
  <div id="mainPage">
    <div id="navBar">
    </div>
    <div id="leftPanel">
    </div>
  </div>
</body>

</html>



回答3:


Make the Div CSS parameter as below:

margin: 0 auto;

This will center your margin.




回答4:


The solution to this issue is very simple. Just remove the hashtag (#) from the 'body' like this:

    body{.....}

There is no need to ever use hashtags for unique HTML tags.




回答5:


Add the html and body styling.

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



回答6:


Remove the # from #body in your CSS.

Your CSS should be...

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


来源:https://stackoverflow.com/questions/44080173/how-can-i-get-rid-of-the-gap-at-the-edge-of-the-page

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