<nav>元素不显示顶部填充

时间:2016-09-29 13:27:01

标签: html css html5

我正在使用HTML5元素设计网站。使用以下HTML5和CSS代码,菜单的顶部填充有一些异常。

&#13;
&#13;
/* 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;
}
&#13;
<nav>
  <a href="">Menu 1</a>
  <a href="">Menu 2</a>
  <a href="">Menu 3</a>
</nav>
&#13;
&#13;
&#13;

This is the output screenshot:

菜单的填充有什么问题?

1 个答案:

答案 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>