0

在以下示例中 - 悬停在子元素上时是否可以保留顶级导航的边框?当悬停在其子项目上时,我想保留“关于我们”的黑色边框。示例:http: //jsfiddle.net/6zKRC/2/

HTML

<div class="navigation">
  <ul class="navigation fc">
   <li>
    <a href="/">Home</a>
   </li>
   <li class="">
    <a href="/about.aspx">About</a>
    <ul>
      <li>
        <a href="/about/sub-navigation-1.aspx">Sub Navigation 1</a>
      </li>
      <li>
        <a href="/about/sub-navigation-2.aspx">Sub Navigation 2</a>
      </li>
    </ul>
  </li>
 </ul>
</div>​

CSS

.navigation ul {
  font-family: Arial, Verdana;
  font-size: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.navigation ul li {
  display: block;
  position: relative;
  float: left;
}

.navigation li ul {
    display: none; 
}

.navigation ul li a {
  display: block;
  text-decoration: none;
  color: #000;
  font-weight:bold;
  padding: 5px 15px 5px 15px;
  white-space: nowrap;
}

.navigation ul li a:hover { 
  background: #CCC;
  color:black;
  border:solid 1px black;
  border-bottom:0;
}

.navigation li:hover ul {
  display: block;
  position: absolute;
  border:solid 1px black;
  border-top:0;
}

.navigation li:hover li {
  float: none;
  font-size: 11px;
}

.navigation li:hover a {
  background: #CCC; 
}

.navigation li:hover li a:hover {
  background: #CCC;
  border:0;
}

​</p>

4

2 回答 2

1

嗨,我对您的 css 进行了一些更改,请检查您更新的 css :-

CSS

.navigation ul {
  font-family: Arial, Verdana;
  font-size: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.navigation ul li {
  display: block;
  position: relative;
  float: left;
}
.navigation li ul {
    display: none; 
}
.navigation ul li a {
  display: block;
  text-decoration: none;
  color: #000;
  font-weight:bold;
  padding: 5px 15px 5px 15px;
  white-space: nowrap;
}
.navigation ul li:hover { 
  background: #CCC;
  color:black;
  border:solid 1px black;
  border-bottom:0;
}
.navigation li:hover ul {
  display: block;
  position: absolute;
  border:solid 1px black;
  border-top:0;
    left:-1px;
} 
.navigation li:hover ul li {
  float: none;
  font-size: 11px;
      background: #CCC; 

}
.navigation li:hover li:hover {
  background:#e6e6e6;
  border:0;
}

HTML

<div class="navigation">
  <ul class="navigation fc">
   <li>
    <a href="/">Home</a>
   </li>
   <li class="">
    <a href="/about.aspx">About</a>
    <ul>
      <li>
        <a href="/about/sub-navigation-1.aspx">Sub Navigation 1</a>
      </li>
      <li>
        <a href="/about/sub-navigation-2.aspx">Sub Navigation 2</a>
      </li>
    </ul>
  </li>
 </ul>
</div>​

我希望你看这个:- http://jsbin.com/uwemuy/5/edit

于 2012-05-30T10:13:31.683 回答
1

在css中更改如下

.navigation li:hover a {
     background: #CCC; 
     border:solid 1px black;
}

http://jsfiddle.net/6zKRC/2/

于 2012-05-30T10:03:50.117 回答