2016-11-20 81 views
-3

我想摆脱我的网站周围的白色边缘。我已设置#body #header和#html页边距:0;和填充:0;是否有人可以帮助与身体,标题和html设置在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; 

} 

下面是该网站的picure Website

回答

-2

试试这个:

* { 
    margin: 0; 
} 

它应该在每个元素上设置所有边距为0。 你可以通过将它保留在你的CSS的开始并向其他元素添加不同的边距

1

你需要从#html,body和header中删除#,因为#用于ID和。 for class 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; 

} 
0

欢迎来到StackOverflow!

您没有正确引用一些元素。 #选择器(在你的CSS前面的html,bodyheader)目标元素用id属性设置后的值为#

由于您试图引用没有ID的HTML元素,因此您的CSS没有正确定位元素。

要修复它,您必须删除htmlbody前面的#。您还可以更简洁,通过使用多个选择这样写:

html, body { 
    margin: 0 !important; 
    padding: 0 !important; 
} 

FYI您在使用header代替head一个小的失误。


如果你正在学习HTML和CSS我推荐以下资源:

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>