【问题标题】:Div padding not disappearing; white borderDiv 填充没有消失;白色边框
【发布时间】:2016-06-06 02:13:52
【问题描述】:

#page-container {
  position: absolute;
  margin: 0px;
  padding: 0px;
  border: 0px;
}
#header {
  background-color: #f9f8e5;
  margin-left: 0px;
  margin-right: 0px;
  margin-bottom: 20px;
  margin-top: -10px;
  padding: 0px;
  border: 0px;
  width: 100%;
  height: 200px;
}
<div id="container">

  <div id="header">
    <center>
      <br>
      <a href="index.html">
        <img src="images/logo.png">
      </a>
    </center>
  </div>

</div>

只是一个快速的解决方案,解决方案可能有点明显并且让我望而却步,基本上我的网站的容器 div 周围有一个边框,边距、填充和边框都设置为 0,所以为什么边框仍然存在我不知道。背景颜色填充在“标题”div 上,从这里我可以看到 div 两侧明显的白线。任何帮助表示赞赏,代码如下。

CSS:

#page-container 
{
position:absolute;
margin: 0px;
padding: 0px;
border: 0px;
}

#header 
{
background-color: #f9f8e5;
margin-left: 0px;
margin-right: 0px;
margin-bottom: 20px;
margin-top: -10px;
padding: 0px;
border: 0px;
width: 100%;
height: 200px;
}

HTML:

<div id="container">

        <div id="header">
        <center>
        <br>
        <a href="index.html"><img src="images/logo.png"></a>
        </center>
        </div>

<REST OF WEBPAGE>

</div>

【问题讨论】:

标签: html css padding margins


【解决方案1】:

&lt;body&gt; 元素在浏览器中默认设置了边距。设置body { margin:0; },你就不应该有边距了。

【讨论】:

  • 这是赢家,没有意识到我也必须将正文设置为 0 边距。谢谢。
【解决方案2】:

css

body {
  margin: 0px;
}
#page-container 
{
position:absolute;
margin: 0px;
padding: 0px;
border: 0px;
}

#header 
{
background-color: #f9f8e5;
margin-left: 0px;
margin-right: 0px;
margin-bottom: 20px;
margin-top: -10px;
padding: 0px;
border: 0px;
width: 100%;
height: 200px;
}

https://jsfiddle.net/ozbkr3sL/

当然你没有为页面提供完整的代码,但是这个 css 应该会有所帮助。

【讨论】:

    【解决方案3】:

    您应该为主体本身设置所需的颜色和属性,而不仅仅是容器。在背景中放入不同的颜色以进行测试。从您发布的 sn-p 来看,这是我能看到的最好的。如果你有一个完整的链接会有所帮助。

    body{ margin:0; }

    body{
        margin: 0px;
        padding: 0px;
        border: 0px;
        color: yellow;
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-01
      • 2018-08-09
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2016-05-16
      • 2018-12-10
      相关资源
      最近更新 更多