因此,我已经开始为我的投资组合网站制定一些基础知识。我已经完成了导航栏,但现在在测试跨浏览器时,它在导航下方显示了几个像素的边距。这在除 Firefox 之外的所有浏览器中都会发生。这让我有点困惑,因为所有元素都有绝对定位。
HTML:
<div id="topnav">
<ul>
<li><a href="index.html" id="current">Home</a></li>
<li><a href="about.html">About Me</a></li>
<li><a href="portfolio.html">Portfolio</a></li>
<li><a href="contact.html" class="lastli">Contact Me</a></li>
</ul>
</div>
这个 div 位于一个容器内,容器宽度为 800,顶部边距为 20px,两侧为 auto。 填充和边距设置为 0。“top:195”用于将栏定位在我的标题图片(800x195)下方。另请注意:列表项具有 1x20 背景渐变图像,设置为 repeat-x。
CSS:
#topnav {
width:800px;
position:absolute;
top:194px;
height:20px;
}
#topnav ul {
list-style-type:none;
text-align:center;
height:20px;
margin:0;
padding:0;
}
#topnav ul li {
display:inline;
font-size:15px;
line-height:20px;
}
#topnav ul li a {
padding:0 10px;
position:relative;
border-left:1px solid white;
margin-left:-6px;
}
请注意,我曾多次尝试将高度设置为 20px,但似乎没有任何效果。我也改了字体,没用。 此处截图:http://imgur.com/a/DKkDy 顶部是 Firefox(如我所愿),底部是 Chrome。 这是一个 JSFiddle:http://jsfiddle.net/SUmF7/
最佳答案
您是否尝试过将 CSS 重置到您的样式表中?
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
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;
}
关于html - 除 Firefox 之外的所有浏览器中的不需要的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8034260/