首页 > 解决方案 > 为什么即使我没有设置任何保证金,我也会得到默认保证金?

问题描述

我已将类设置mainBackground为 div。尽管我只设置了背景颜色,但我从 chrome 窗口的各个方面都得到了一个边距。我的代码如下:

     .mainBackground {
            background-color: #ece8e8;
            width: 100%;
        }

    <div class="mainBackground">
        hello
    </div>

我想删除该 div 标签的边距。

标签: htmlcsssass

解决方案


* {
  margin: 0;
  padding: 0;
}
.mainBackground {
  background-color: #ece8e8;
  width: 100%;
  padding: 100px 0;
  text-align: center;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<div class="mainBackground">
    hello
</div>
</body>
</html>

给保证金:0;和 padding: 0 每个元素!希望它会有所帮助


推荐阅读