如果我现在运行标记,则<li>
元素不在<ul>
元素内。但是如果我添加这种样式display:block;
,#nav a
那么完整的#nav a
声明看起来像这样,那么<li>
元素就在<ul>
.
#nav a {
display:block;
margin:0;
padding:8px 16px;
color:#333;
text-decoration:none;
border:1px solid #9B8748;
border-bottom:none;
background:#F9E9A9;
}
任何人都可以解释为什么<li>
元素<ul>
在我添加display:block
到的范围内#nav a
吗?
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
font-family:Arial, sans-serif;
font-size:small;
width:720px;
margin:0;
padding:0;
}
#nav {
float:left;
width:100%;
margin:0;
padding:10px 0 0 46px;
list-style:none;
background:#FFCB2D;
}
#nav li {
float:left;
margin:0 1px 0 0;
padding:0;
font-family:"Lucida Grande", "sans-serif";
font-size:90%;
}
#nav a {
/* display:block;*/
margin:0;
padding:8px 16px;
color:#333;
text-decoration:none;
border:1px solid #9B8748;
border-bottom:none;
background:#F9E9A9;
}
#nav a:hover {
color:#333;
padding-bottom:5px;
border-color:#727377;
background:#fff;
}
</style>
<meta charset="utf-8" />
<title>Chapter 3</title>
</head>
<body>
<ul id="nav">
<li id="t-intro"><a href="/">Introduction</a></li>
<li id="t-about"><a href="about.html">About Lance</a></li>
<li id="t-news"><a href="news.html">News & Events</a></li>
<li id="t-sponsors"><a href="sponsors.html">Sponsors</a></li>
</ul>
</body>
</html>