我正在使用HTML5元素设计网站。使用以下HTML5和CSS代码,菜单的顶部填充有一些异常。
/* CSS Resets */
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;
}
/* CSS Resets end */
/* CSS document starts */
body {
background-color: #e4deaf;
margin: 0;
padding: 0;
}
nav {
display: block;
}
a {
text-decoration: none;
color: #808080;
border: 1px dashed black;
border-radius: 7px;
padding: 1em 3em;
}
a:hover {
background-color: #ffbc6a;
}
a:active {
background-color: #e4deaf;
}

<nav>
<a href="">Menu 1</a>
<a href="">Menu 2</a>
<a href="">Menu 3</a>
</nav>
&#13;
This is the output screenshot:
菜单的填充有什么问题?
答案 0 :(得分:2)
这是因为inline
元素上的display
属性的a
默认值。尝试使用inline-block
进行更改,然后就可以了。
/* CSS Resets */
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;
}
/* CSS Resets end */
/* CSS document starts */
body {
background-color: #e4deaf;
margin: 0;
padding: 0;
}
nav {
display: block;
}
a {
text-decoration: none;
color: #808080;
border: 1px dashed black;
border-radius: 7px;
padding: 1em 3em;
display: inline-block;
}
a:hover {
background-color: #ffbc6a;
}
a:active {
background-color: #e4deaf;
}
<nav>
<a href="">Menu 1</a>
<a href="">Menu 2</a>
<a href="">Menu 3</a>
</nav>