为什么我的UL菜单不起作用?

时间:2010-08-04 12:49:55

标签: html css navigation

这是HTML:

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>Hi World!</title>

<link rel="stylesheet" type="text/css" href="c/main.css?95" />

</head>
<body>
<div id="wrapper">
  <div id="divider">
  <h1>LOGO</h1>
  <ul class="underlinemenu">
    <li>menu item</li> 
    <li>menu item</li>
    <li>menu item</li> 
    <li>menu item</li>
    <li>menu item</li> 
    <li>menu item</li>
  </ul>
  </div> <!-- end divider -->

  <div id="divider">
  <div class="article">
    <h2 class="header">HEADER</h2>
    <div class="content">
      <p>CONTENT CONTENT CONTENT</p>
      <p>CONTENT CONTENT CONTENT</p>
      <p>CONTENT CONTENT CONTENT</p>
    </div>
  </div>
  </div> <!-- end divider -->

  <div id="divider">
  <div class="article">
    <h2 class="header">HEADER</h2>
    <div class="content">
      <p>CONTENT CONTENT CONTENT</p>
      <p>CONTENT CONTENT CONTENT</p>
      <p>CONTENT CONTENT CONTENT</p>
    </div>
  </div>
  </div> <!-- end divider -->

  <div id="divider">
  <div class="article">
    <h2 class="header">HEADER</h2>
    <div class="content">
      <p>CONTENT CONTENT CONTENT</p>
      <p>CONTENT CONTENT CONTENT</p>
      <p>CONTENT CONTENT CONTENT</p>
    </div>
  </div>
  </div> <!-- end divider -->

  <div id="footer">
    <p class="copyright">COPYRIGHT</p>
    <ul id="sitemap">
      <li>menu item</li>
      <li>menu item</li>
      <li>menu item</li>
      <li>menu item</li>
    </ul>
  </div>
</div> <!-- end wrapper -->
</body>
</html>

这是我的CSS:

/* LAYOUT */
/* ----------------------------------------- */

div#wrapper {
    margin: 0 auto;
    width: 936px;
}

div#divider {
    border-bottom: 1px dotted #c5c5c5;
    margin: 0 0 10px 0;
    padding: 0 0 10px 0;
}
/*Credits: Dynamic Drive CSS Library */
/*URL: http://www.dynamicdrive.com/style/ */

.underlinemenu{
font-weight: bold;
width: 100%;
}

.underlinemenu ul{
padding: 6px 0 7px 0; /*6px should equal top padding of "ul li a" below, 7px should equal bottom padding + bottom border of "ul li a" below*/
margin: 0;
text-align: right; //set value to "left", "center", or "right"*/
}

.underlinemenu ul li{
display: inline;
}

.underlinemenu ul li a{
color: #494949;
padding: 6px 3px 4px 3px; /*top padding is 6px, bottom padding is 4px*/
margin-right: 20px; /*spacing between each menu link*/
text-decoration: none;
border-bottom: 3px solid gray; /*bottom border is 3px*/
}

.underlinemenu ul li a:hover, .underlinemenu ul li a.selected{
border-bottom-color: black;
}

我做错了什么?

1 个答案:

答案 0 :(得分:3)

你的CSS选择器有一个错误。你的规则应该是:

ul.underlinemenu {
   // rules that will target the <ul>
}

ul.underlinemenu li {
   // rules that will target the nested <li>'s
}

ul.underlinemenu li a {
   // rules that will target the nested <a>'s
}

之所以这样,是因为您尝试使用类<ul>设置underlinemenu样式。您所拥有的是尝试设置嵌套在具有类<ul>的另一个元素内的underlinemenu