This question already has answers here:
How to remove white space left and right side of page?
(4个答案)
三年前关闭。
我想去掉黑暗部门左右两边的空白。我怎样才能做到这一点?我在google上搜索到的只是添加padding:0px;和margin:0px;但这不起作用。有什么想法吗?
/*Start of header styling*/

#header {
  background-color: RGB(57, 89, 100);
  Height: 75px;
  left: 0;
  top: 0;
  position: absolute;
  width: 100%;
}
/*End of header styling*/

body {
  display: block;
}
#subHead {
  background-color: RGB(39, 39, 39);
  height: 100px;
  padding: 0px;
  margin: 0px;
  height: 350px;
}
/*Start of footer styling*/

/*End of footer styling*/

<div id="header">
  <h1>&zwj;</h1>
</div>

<div id="subHead">
  <h1>&zwj;</h1>
</div>

最佳答案

通过添加重置CSS

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

通常,这样的默认样式的CSS重置会应用到文档中,这样您就可以从头开始了。Here是关于重置CSS样式表的一些重要信息。
html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}
#header {
  background-color: RGB(57, 89, 100);
  Height: 75px;
  left: 0;
  top: 0;
  position: absolute;
  width: 100%;
}

#subHead {
  background-color: RGB(39, 39, 39);
  height: 100px;
  padding: 0px;
  margin: 0px;
  height: 350px;
}

<div id="header">
  <h1>&zwj;</h1>
</div>

<div id="subHead">
  <h1>&zwj;</h1>
</div>

关于html - 如何摆脱div左右两侧的空白? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34302798/

10-11 14:47