我的页眉导航 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
另一种解决方法是设置一个负的 margin-top 值。但它为什么以及如何存在?
最佳答案
始终使用重置样式
* {
margin: 0;
padding: 0;
}
Using a CSS Reset, CSS authors can force every browser to have all its styles reset to null, thus avoiding cross-browser differences as much as possible.
更高级的 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
关于出现 CSS 未知边距/填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19488113/