设置边距为0后正文包含白色(Vanilla HTML And CSS)[重复]

y0u0uwnf  于 2023-02-26  发布在  其他
关注(0)|答案(2)|浏览(111)
    • 此问题在此处已有答案**:

How wide is the default <body> margin?(4个答案)
昨天关门了。
我试图制作一个英雄图像,在两侧没有空白。由于某种原因,我仍然得到他们,即使在检查元素,发现这是我的身体的边距,并设置为0

.body {
    font-family: 'Times New Roman', Times, serif;
    margin: 0;
    padding: 0;
}
.navigation {
    margin: 0;
    overflow: hidden;
    width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 15px;
}

a {
  text-decoration: none;
  font-weight: light;
}

.navigation-inner {
  background: #eaeae4;
  border-radius: 5px;
  overflow: hidden;
}

.navigation-inner {
  font-size: 28px;
  display: flex;
}

.notification-round {
  background: rgba(240,0,0,.6);
  color: white;
  padding: 0 8px;
  border-radius: 50%;
  font-size: 16px;
  margin-left: 3px;
}

.navigation-link {
  padding: 15px 20px 10px 20px;
  display: inline-block;
  color: rgba(0,0,0,.7);
  transition: all .2s ease-in-out;
  border-bottom: 4px solid transparent;
}

.navigation-link:hover {
  background: rgba(50,50,0,.1);
  border-bottom-color: #8acc84;
}

.navigation-link > i {
  padding-right: 8px;
}

/*HERO*/

#home {
    background-size:
}

.hero-image {
    background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.1)), url("../images/furniture.jpg");
    height: 400px;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    position: relative;
}
.hero-text {
    text-align: center;
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
  }
.hero-text h1 {
    font-size: 50px;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bill's Furniture Emporium</title>
    <link rel="stylesheet" href="./css/one_page_website.css">
</head>
<body>
<!-- NAV -->
    <div class = "navigation">
        <header class="navigation-shadow">
            <div class = "navigation-inner">
                <a href="#home" class="navigation-link" id="link">HOME</a>
                <a href="#gallery" class="navigation-link" >GALLERY</a>
                <a href="#contact" class="navigation-link" >CONTACT</a>
            </div>
        </header>
    </div>
<!--HOMEPAGE-->
    <div id="home">
        <div class="hero-image">
            <div class="hero-text">
              <h1>Bill's Furniture Emporium</h1>
            </div>
        </div>
    </div>
</body>
</html>

我试着检查元素并删除边距和填充,但没有效果

jogvjijk

jogvjijk1#

问题是您在css中使用了类选择器:

.body

何时应使用元素选择器:

body

从你的css中删除这个点,它应该可以工作。

bfrts1fy

bfrts1fy2#

你应该设置根也,尝试添加这个:

*{
  margin: 0;
  padding: 0;
}

了解更多here.

相关问题