无法在Hover - Bootstrap Navbar上更改字体颜色

时间:2015-11-03 05:44:33

标签: html css twitter-bootstrap navbar

所以,我有一个子导航栏,在悬停时只改变<li>而不是文本的颜色。这是我的代码供您参考。我错过了什么?我确信这是一个非常小的东西,我忽略了。

.section-navbar {
    margin: -10px 0 0 -12px;
}

.section-navbar>ul {
    margin: 0px 0 -35px 0px;
    padding: 2px 0px;
    background-color: #ececec;
    height: 32px;
}

.section-navbar>ul>li {
    display: block;
    float: left;
    height: 30px;
    text-align: center;
    background-color: #ececec;
    border-right-color: #fff;
    border-right-width: thin;
    border-right-style: solid;
    border-radius: 2px;
    font-weight: normal;
    font-size: 12px;
    padding: 5px 20px;
}

.section-navbar>ul>li>a {
    display: inline-block;
    color: #999;
    text-decoration: none;
}

.section-navbar>ul>li.active {
    background-color: #0083ca;
    border-radius: 2px;
    border-top-color: #359dd5;
    border-top-style: solid;
    border-top-width: medium;
    text-decoration: none;
    padding: 7px 20px;
    margin-top: -5px;
    color: #fff;
    font-weight:bold;
    letter-spacing:0.5px;
    height: 35px;
}

.section-navbar>ul>li:hover {
    background-color: #0083ca;
    border-radius: 2px;
    border-top-color: #359dd5;
    border-top-style: solid;
    border-top-width: medium;
    text-decoration: none;
    margin: -5px 0;
    height:35px;
    color: #fff;
}
<div class="section-navbar">
  <ul>
      <li><a href="#">Search</a></li>
      <li><a href="#">Option 2</a></li>
      <li class="active">Lorem ipsum dolor sit</li>
      <li><a href="#">Option 4</a></li>
  
  </ul>
</div>

3 个答案:

答案 0 :(得分:2)

.section-navbar {
    margin: -10px 0 0 -12px;
}

.section-navbar>ul {
    margin: 0px 0 -35px 0px;
    padding: 2px 0px;
    background-color: #ececec;
    height: 32px;
}

.section-navbar>ul>li {
    display: block;
    float: left;
    height: 30px;
    text-align: center;
    background-color: #ececec;
    border-right-color: #fff;
    border-right-width: thin;
    border-right-style: solid;
    border-radius: 2px;
    font-weight: normal;
    font-size: 12px;
    padding: 5px 20px;
}

.section-navbar>ul>li>a {
    display: inline-block;
    color: #999;
    text-decoration: none;
}

.section-navbar>ul>li.active {
    background-color: #0083ca;
    border-radius: 2px;
    border-top-color: #359dd5;
    border-top-style: solid;
    border-top-width: medium;
    text-decoration: none;
    padding: 7px 20px;
    margin-top: -5px;
    color: #fff;
    font-weight:bold;
    letter-spacing:0.5px;
    height: 35px;
}

.section-navbar > ul > li:hover a {color:red}

.section-navbar>ul>li:hover {
    background-color: #0083ca;
    border-radius: 2px;
    border-top-color: #359dd5;
    border-top-style: solid;
    border-top-width: medium;
    text-decoration: none;
    margin: -5px 0;
    height:35px;
    color: red!important;
}
<div class="section-navbar">
  <ul>
      <li><a href="#">Search</a></li>
      <li><a href="#">Option 2</a></li>
      <li class="active">Lorem ipsum dolor sit</li>
      <li><a href="#">Option 4</a></li>
  
  </ul>
</div>

答案 1 :(得分:1)

你必须在下面给出的这个课程中工作。

   .section-navbar > ul > li:hover a {
     color:red
    }

答案 2 :(得分:1)

:hover添加了a样式。还将填充更改为a,以便整个区域可以点击。

&#13;
&#13;
.section-navbar {
margin: -10px 0 0 -12px;
}

.section-navbar>ul {
margin: 0px 0 -35px 0px;
padding: 2px 0px;
background-color: #ececec;
height: 32px;
}

.section-navbar>ul>li {
display: block;
float: left;
height: 30px;
text-align: center;
background-color: #ececec;
border-right-color: #fff;
border-right-width: thin;
border-right-style: solid;
border-radius: 2px;
font-weight: normal;
font-size: 12px;
}

.section-navbar>ul>li>a {
display: inline-block;
color: #999;
text-decoration: none;
padding: 5px 20px;
height: 25px;
}
.section-navbar>ul>li>a:hover{
color: #fff;
}
.section-navbar>ul>li.active {
background-color: #0083ca;
border-radius: 2px;
border-top-color: #359dd5;
border-top-style: solid;
border-top-width: medium;
text-decoration: none;
padding: 7px 20px;
margin-top: -5px;
color: #fff;
font-weight:bold;
letter-spacing:0.5px;
height: 35px;
padding: 5px 20px;
}

.section-navbar>ul>li:hover {
background-color: #0083ca;
border-radius: 2px;
border-top-color: #359dd5;
border-top-style: solid;
border-top-width: medium;
text-decoration: none;
margin: -5px 0;
height:35px;
color: #fff;
}
&#13;
<div class="section-navbar">
  <ul>
  <li><a href="#">Search</a></li>
  <li><a href="#">Option 2</a></li>
  <li class="active">Lorem ipsum dolor sit</li>
  <li><a href="#">Option 4</a></li>
  
  </ul>
</div>
&#13;
&#13;
&#13;