英文:
Body contains white spaces after setting margin to 0 (Vanilla HTML And CSS)
问题
我正在尝试创建一个没有侧边空白的英雄图像。不知何故,即使在检查元素并发现是我的body的margin,并将其设置为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;
}
希望这可以帮助您解决问题。
英文:
I am trying to make a hero image with no white spaces on the sides. For some reason I am still getting them even after inspecting the element and finding out that it was my body's margin, and setting that to 0
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.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;
}
<!-- language: lang-html -->
<!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>
<!-- end snippet -->
I tried inspecting the element and removing the margin and padding yet it didn't work
答案1
得分: 1
你应该同时设置根元素,尝试添加以下内容:
*{
margin: 0;
padding: 0;
}
在此处阅读更多信息点击这里。
答案2
得分: 1
问题在于你在你的CSS中使用了一个类选择器:
.body
而你应该使用一个元素选择器:
body
从你的CSS中去掉点号,然后它应该可以工作。
英文:
The issue is that you are using a class selector in your css:
.body
when you should be using an element selector:
body
Remove the dot from your css and it should work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论