为什么子菜单标签需要父li css?

时间:2012-02-09 17:26:31

标签: html css

所以我正在创建一个菜单,子菜单标签采用父li菜单css - color,font-size,font-weight e.c.我该如何解决这个问题?好吧,我已经为li元素设置了相同的大小和权重,因为它应该是子菜单元素,但是设置父li元素的颜色,不解决问题,href应该有不同。

代码 -

#top-menu-wrapper #menu {
  float: left;
  margin-left: 45px;
  height: 81px;
  width: auto;
}

#top-menu-wrapper #menu ul {
  list-style: none;
  padding: 0;
  width: auto;
  margin: 0;
  margin-top: 30px;
  float: left; 
}

#top-menu-wrapper #menu ul li {
  margin: 0;
  padding: 0;
  display: inline;
  margin-left: 20px;
  float: left;
  background-image: url('../images/down.png');
  background-repeat: no-repeat;
  padding-right: 10px;
  background-position: right 9px;
  height: 50px;
  font-weight: bold;
  font-size: 12px;
}   

#top-menu-wrapper #menu ul li span {
  font-size: 9px;
  color: #b9e5f9;  
}

#top-menu-wrapper #menu ul li:hover span {
  padding-bottom: 5px;
  border-bottom: 2px solid #b9e5f9;
}

#top-menu-wrapper #menu ul li:hover{
  margin: 0;
  padding: 0;
  display: inline;
  margin-left: 20px;
  float: left;
  background-image: url('../images/down-hover.png');
  background-repeat: no-repeat;
  padding-right: 10px;
  background-position: right 9px;
  height: 50px;  
}   

#top-menu-wrapper #menu ul li:hover span {
  font-size: 9px;
  color: #5e5e5e;
}

#top-menu-wrapper #menu ul li a.menu {
  color: #5e5e5e;
  font-weight: bold;
  font-size: 15px;
  text-decoration: none;   
}

#top-menu-wrapper #menu ul li a.menu:hover {
  color: #b9e5f9;
  font-weight: bold;
  font-size: 15px;
  text-decoration: none;      
}

#top-menu-wrapper #menu ul li ul {
  display: none;    
} 

#top-menu-wrapper #menu ul li:hover ul {
  display: block;
  position: absolute;
  width: 170px;
  margin:0;
  margin-top: 17px;
  padding:0;
  height: 100px;
  background: url('../images/menu-dropdown-bg.png');
  z-index: 200;
  behavior: url(ie-css3.htc);
  border-bottom-right-radius:5px;
  -webkit-border-bottom-right-radius:5px;
  -moz-border-bottom-right-radius: 5px;
  -khtml-border-bottom-right-radius: 5px;
  border-bottom-left-radius:5px;
  -webkit-border-bottom-left-radius:5px;
  -moz-border-bottom-left-radius: 5px;
  -khtml-border-bottom-left-radius: 5px;  
} 

#top-menu-wrapper #menu ul li:hover ul li {
  width: 150px;
  height: 20px;
  border-bottom: 1px solid #eeeeee;
  padding: 0px;
  margin: 0px;
  margin-left: 10px;
  background: none;
  padding-top: 7px;
  padding-bottom: 5px;
}

#top-menu-wrapper #menu ul li:hover ul li a.submenu {
  color: #5e5e5e;
  text-decoration: none;
  padding-left: 10px;
  font-size: 12px;
  font-weight: bold;
}

#top-menu-wrapper #menu ul li:hover ul li a.submenu:hover {
  color: #b9e5f9;
  text-decoration: none;
  padding-left: 10px;
  font-size: 12px;
  font-weight: bold;
}

HTML -

     <div id="menu">
       <ul>
         <li style="background: none;"><a href="#" class="menu">Home</a><br /><span>To first page</span></li>
         <li><a href="#" class="menu">Services</a><br /><span>Various Hands</span>
    <ul>
      <li><a href="#" class="submenu">Features</a></li>
    </ul>
   </li>
         <li><a href="#" class="menu">Portfolio</a><br /><span>Our Works</span></li>
         <li><a href="#" class="menu">Journal</a><br /><span>Our Stories</span></li>
         <li><a href="#" class="menu">Contact Us</a><br /><span>Reach us now</span></li>
       </ul>
     </div>

1 个答案:

答案 0 :(得分:2)

我学到的一个重要经验是使用基于列表的菜单:不要设置LI标签的样式(定位和显示除外),将所有样式放在A标签上并使用{{1} }