我想摆脱我网站周围的白边。我已经设置#body #header和#html margin:0;和填充:0;有人可以帮忙吗
以下是HTML代码:
<DOCTYPE html>
<html>
<header>
<link href="CSS/stylesheet.css" rel=stylesheet>
</header>
<body>
<div id="bannertop"></div>
</body>
</html>
CSS:
#html{
margin: 0 !important;
padding: 0 !important;
}
#header{
margin: 0 !important;
padding: 0 !important;
}
#body{
margin: 0 !important;
padding: 0 !important;
}
#bannertop{
height: 200px;
width: 100%;
background-color: cadetblue;
margin-top:0px;
}
这是该网站的图片 Website
答案 0 :(得分:1)
你需要从html,body和header中删除#,因为#use用于ID和。课程difference between ID & Class
html,body{
margin: 0 !important;
padding: 0 !important;
}
header{
margin: 0 !important;
padding: 0 !important;
}
#bannertop{
height: 200px;
width: 100%;
background-color: cadetblue;
margin-top:0px;
}
答案 1 :(得分:0)
欢迎使用StackOverflow!
您没有正确引用某些元素。 #
选择器(在html
前面,body
和header
在CSS中)目标元素id
属性设置{{1之后的值}}
由于你的HTML元素,你试图引用没有ID,你的CSS没有正确地定位元素。
要解决此问题,您必须删除#
和#
前面的html
。您还可以使用多个选择器更简洁地编写它:
body
仅供参考,您使用html, body {
margin: 0 !important;
padding: 0 !important;
}
代替header
时会出现轻微错误。
如果您目前正在学习HTML和CSS,我建议使用以下资源:
答案 2 :(得分:0)
在正文和html
之前删除#
html{
margin: 0 !important;
padding: 0 !important;
}
#header{
margin: 0 !important;
padding: 0 !important;
}
body{
margin: 0 !important;
padding: 0 !important;
}
#bannertop{
height: 200px;
width: 100%;
background-color: cadetblue;
margin-top:0px;
}
<DOCTYPE html>
<html>
<header>
<link href="CSS/stylesheet.css" rel=stylesheet>
</header>
<body>
<div id="bannertop"></div>
</body>
</html>
答案 3 :(得分:-2)
试试这个:
* {
margin: 0;
}
它应该在每个元素上将所有边距设置为0。 你可以通过将它保持在css的开头并为其他元素添加不同的边距来覆盖它