我的标头导航ID标签之间似乎有未知的边距或填充。
以下是div标签:
<div id="container">
<div id="header">
<p align="center">HEADER</p>
</div>
<div id="navi">
<p align="center">NAVIGATION</p>
</div>
</div>
随之而来的样式表:
#container
{
width: 800px;
background-color: #AFAF97;
margin: 0px auto;
}
#header
{
height: 75px;
width: 100%;
background-color: #888888;
}
#navi
{
height: 50px;
width: 100%;
background-color: #aaaaaa;
/*margin-top: -16px;*/
}
这是未知边距/填充的屏幕截图。 http://imgur.com/l37DVFc
另一种解决方法是设置负的保证金最高值。但为什么以及如何呢?
答案 0 :(得分:4)
始终使用重置样式
* {
margin: 0;
padding: 0;
}
使用CSS重置,CSS作者可以强制每个浏览器都拥有它 样式重置为null,从而避免了跨浏览器的差异 尽可能。
更高级的css重置。
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
固定:demo
答案 1 :(得分:2)
答案 2 :(得分:1)
进入css
* {
margin:0;
padding:0;
}
答案 3 :(得分:0)