2017-03-19 57 views
0

我对我的下拉菜单中的文字颜色有疑问。下拉文字颜色基于主链接文字颜色。当我选择该链接时,它会更改为当前标签颜色,但也会更改下拉文本颜色。我想知道如何使下拉菜单的颜色与主选项卡文本颜色无关。更改当前标签下拉菜单颜色

下面是HTML:

<nav id="nav-wrap"> 

      <a class="mobile-btn" href="#nav-wrap" title="Show navigation">Show navigation</a> 
      <a class="mobile-btn" href="#" title="Hide navigation">Hide navigation</a> 

      <ul id="nav" class="nav"> 

       <li><a href="index.html">Home</a></li> 
       <li class="current"><a href="blog.html">Blog</a> 
       </li> 
       <li><span><a href="portfolio-index.html">Resources</a></span> 
       <ul> 
        <li><a href="alcoholre.html">Alcohol</a></li> 
        <li><a href="drugsre.html">Drugs</a></li> 
        <li><a href="mentalhealthre.html">Mental Health</a></li> 
        <li><a href="suicidere.html">Suicide</a></li> 
       </ul> 
       </li> 
       <li><a href="about.html">About</a></li> 
       <li><a href="contact.html">Contact</a></li> 

      </ul> <!-- end #nav --> 

     </nav> <!-- end #nav-wrap --> 

这里是CSS:

#nav-wrap ul, #nav-wrap li, #nav-wrap a { 
margin: 0; 
padding: 0; 
border: none; 
outline: none; 
} 

/* nav-wrap */ 
#nav-wrap { 
position: relative; 
font: 15px raleway-heavy, sans-serif; 
text-transform: uppercase; 
letter-spacing: 1.5px; 
float: right; 
margin-top: 32px; 
margin-right: 20px; 
z-index: 99999; 
} 

/* hide toggle button */ 
#nav-wrap > a.mobile-btn { 
display: none; 
border-radius: 3px; 
} 

ul#nav { 
min-height: 48px; 
width: auto; 

/* left align the menu */ 
text-align: left; 
} 
ul#nav li { 
position: relative; 
list-style: none; 
height: 48px; 
display: inline-block; 
} 

/* Links */ 
ul#nav li a { 

/* 8px padding top + 8px padding bottom + 32px line-height = 48px */ 

display: inline-block; 
padding: 8px 11px; 
line-height: 32px; 
text-decoration: none; 
text-align: left; 
color: #ffffff; 

-webkit-transition: color .2s ease-in-out; 
-moz-transition: color .2s ease-in-out; 
-o-transition: color .2s ease-in-out; 
-ms-transition: color .2s ease-in-out; 
transition: color .2s ease-in-out; 
} 

ul#nav li a:active { background-color: transparent !important; } 
ul#nav li:hover > a, 
ul#nav li.current a { color: #00b2ee; } 

/* adds down arrow */ 
ul#nav span:after { 
width: 0; 
height: 0px; 
border: 4px solid transparent; 
border-bottom: none; 
border-top-color: #00b2ee; 
content: ''; 
vertical-align: middle; 
display: inline-block; 
position: relative; 
right: 5px; 
} 

/* Sub Menu 
----------------------------------------------------- */ 
ul#nav ul { 
position: absolute; 
top: 100%; 
left: 0; 
background: #c7c7c7; 
min-width: 100%; 


border-radius: 5px 5px 7px 7px; 

/* for transition effects */ 
opacity: 0; 
filter: alpha(opacity=0); 

-webkit-transition: opacity .25s ease .1s; 
-moz-transition: opacity .25s ease .1s; 
-o-transition: opacity .25s ease .1s; 
-ms-transition: opacity .25s ease .1s; 
transition: opacity .25s ease .1s; 
} 

/* Third level sub menu 
ul#nav ul ul { 
position: absolute; 
top: 0; 
left: 100%; 

border-radius: 0 3px 3px 3px; 
} 
*/ 

ul#nav ul li { 
padding: 0; 
display: block; 
text-align: left; 

/* for transition effects */ 
height: 0; 
overflow: hidden; 

-webkit-transition: height .25s ease .1s; 
-moz-transition: height .25s ease .1s; 
-o-transition: height .25s ease .1s; 
-ms-transition: height .25s ease .1s; 
transition: height .25s ease .1s; 
} 

/*On Hover */ 
ul#nav li:hover > ul { 
opacity: 1; filter: alpha(opacity=100); 
} 
ul#nav li:hover > ul li { 
height: 42px; 
overflow: visible; 
border-bottom: 1px solid #26272C; 
color: #ffffff; 
} 
ul#nav li:hover > ul li:last-child { border: none; } 

/* Sub Menu Anchor links */ 
ul#nav ul li a { 
padding: 6px 15px; 
margin: 0; 
white-space: nowrap; 
font-size: 13px; 
} 

任何帮助将是真棒!

回答

0

添加以下在你的CSS脚本结束

ul#nav ul li a:hover{ 
color:red; 
} 

例子:

#nav-wrap ul, #nav-wrap li, #nav-wrap a { 
 
margin: 0; 
 
padding: 0; 
 
border: none; 
 
outline: none; 
 
} 
 

 
/* nav-wrap */ 
 
#nav-wrap { 
 
position: relative; 
 
font: 15px raleway-heavy, sans-serif; 
 
text-transform: uppercase; 
 
letter-spacing: 1.5px; 
 
float: right; 
 
margin-top: 32px; 
 
margin-right: 20px; 
 
z-index: 99999; 
 
} 
 

 
/* hide toggle button */ 
 
#nav-wrap > a.mobile-btn { 
 
display: none; 
 
border-radius: 3px; 
 
} 
 

 
ul#nav { 
 
min-height: 48px; 
 
width: auto; 
 

 
/* left align the menu */ 
 
text-align: left; 
 
} 
 
ul#nav li { 
 
position: relative; 
 
list-style: none; 
 
height: 48px; 
 
display: inline-block; 
 
} 
 

 
/* Links */ 
 
ul#nav li a { 
 

 
/* 8px padding top + 8px padding bottom + 32px line-height = 48px */ 
 

 
display: inline-block; 
 
padding: 8px 11px; 
 
line-height: 32px; 
 
text-decoration: none; 
 
text-align: left; 
 
color: #ffffff; 
 

 
-webkit-transition: color .2s ease-in-out; 
 
-moz-transition: color .2s ease-in-out; 
 
-o-transition: color .2s ease-in-out; 
 
-ms-transition: color .2s ease-in-out; 
 
transition: color .2s ease-in-out; 
 
} 
 

 
ul#nav li a:active { background-color: transparent !important; } 
 
ul#nav li:hover > a, 
 
ul#nav li.current a { color: #00b2ee; } 
 

 
/* adds down arrow */ 
 
ul#nav span:after { 
 
width: 0; 
 
height: 0px; 
 
border: 4px solid transparent; 
 
border-bottom: none; 
 
border-top-color: #00b2ee; 
 
content: ''; 
 
vertical-align: middle; 
 
display: inline-block; 
 
position: relative; 
 
right: 5px; 
 
} 
 

 
/* Sub Menu 
 
----------------------------------------------------- */ 
 
ul#nav ul { 
 
position: absolute; 
 
top: 100%; 
 
left: 0; 
 
background: #c7c7c7; 
 
min-width: 100%; 
 

 

 
border-radius: 5px 5px 7px 7px; 
 

 
/* for transition effects */ 
 
opacity: 0; 
 
filter: alpha(opacity=0); 
 

 
-webkit-transition: opacity .25s ease .1s; 
 
-moz-transition: opacity .25s ease .1s; 
 
-o-transition: opacity .25s ease .1s; 
 
-ms-transition: opacity .25s ease .1s; 
 
transition: opacity .25s ease .1s; 
 
} 
 

 
/* Third level sub menu 
 
ul#nav ul ul { 
 
position: absolute; 
 
top: 0; 
 
left: 100%; 
 

 
border-radius: 0 3px 3px 3px; 
 
} 
 
*/ 
 

 
ul#nav ul li { 
 
padding: 0; 
 
display: block; 
 
text-align: left; 
 

 
/* for transition effects */ 
 
height: 0; 
 
overflow: hidden; 
 

 
-webkit-transition: height .25s ease .1s; 
 
-moz-transition: height .25s ease .1s; 
 
-o-transition: height .25s ease .1s; 
 
-ms-transition: height .25s ease .1s; 
 
transition: height .25s ease .1s; 
 
} 
 

 
/*On Hover */ 
 
ul#nav li:hover > ul { 
 
opacity: 1; filter: alpha(opacity=100); 
 
} 
 
ul#nav li:hover > ul li { 
 
height: 42px; 
 
overflow: visible; 
 
border-bottom: 1px solid #26272C; 
 
color: #ffffff; 
 
} 
 
ul#nav li:hover > ul li:last-child { border: none; } 
 

 
/* Sub Menu Anchor links */ 
 
ul#nav ul li a { 
 
padding: 6px 15px; 
 
margin: 0; 
 
white-space: nowrap; 
 
font-size: 13px; 
 
} 
 
ul#nav ul li a:hover{ 
 
color:red; 
 
}
<nav id="nav-wrap"> 
 

 
      <a class="mobile-btn" href="#nav-wrap" title="Show navigation">Show navigation</a> 
 
      <a class="mobile-btn" href="#" title="Hide navigation">Hide navigation</a> 
 

 
      <ul id="nav" class="nav"> 
 

 
       <li><a href="index.html">Home</a></li> 
 
       <li class="current"><a href="blog.html">Blog</a> 
 
       </li> 
 
       <li><span><a href="portfolio-index.html">Resources</a></span> 
 
       <ul> 
 
        <li><a href="alcoholre.html">Alcohol</a></li> 
 
        <li><a href="drugsre.html">Drugs</a></li> 
 
        <li><a href="mentalhealthre.html">Mental Health</a></li> 
 
        <li><a href="suicidere.html">Suicide</a></li> 
 
       </ul> 
 
       </li> 
 
       <li><a href="about.html">About</a></li> 
 
       <li><a href="contact.html">Contact</a></li> 
 

 
      </ul> <!-- end #nav --> 
 

 
     </nav> <!-- end #nav-wrap -->

+0

太棒了,工作!非常感谢! – epalm18

0

我使用你的代码创建的fiddle。将鼠标悬停在下拉菜单链接上时,文本颜色将变为当前菜单选项卡上使用的蓝色。如果您不想在下拉菜单中将文本悬停在蓝色上,并且想要使用白色文本链接,只需从您的代码中删除“ul#nav li:hover> a”,它会执行工作。现在

新的CSS代码应该是这样的: -

#nav-wrap ul, #nav-wrap li, #nav-wrap a { 
margin: 0; 
padding: 0; 
border: none; 
outline: none; 
} 

/* nav-wrap */ 
#nav-wrap { 
position: relative; 
font: 15px raleway-heavy, sans-serif; 
text-transform: uppercase; 
letter-spacing: 1.5px; 
float: right; 
margin-top: 32px; 
margin-right: 20px; 
z-index: 99999; 
} 

/* hide toggle button */ 
#nav-wrap > a.mobile-btn { 
display: none; 
border-radius: 3px; 
} 

ul#nav { 
min-height: 48px; 
width: auto; 

/* left align the menu */ 
text-align: left; 
} 
ul#nav li { 
position: relative; 
list-style: none; 
height: 48px; 
display: inline-block; 
} 

/* Links */ 
ul#nav li a { 

/* 8px padding top + 8px padding bottom + 32px line-height = 48px */ 

display: inline-block; 
padding: 8px 11px; 
line-height: 32px; 
text-decoration: none; 
text-align: left; 
color: #ffffff; 

-webkit-transition: color .2s ease-in-out; 
-moz-transition: color .2s ease-in-out; 
-o-transition: color .2s ease-in-out; 
-ms-transition: color .2s ease-in-out; 
transition: color .2s ease-in-out; 
} 

ul#nav li a:active { background-color: transparent !important; } 
ul#nav li.current a { color: #00b2ee; } 

/* adds down arrow */ 
ul#nav span:after { 
width: 0; 
height: 0px; 
border: 4px solid transparent; 
border-bottom: none; 
border-top-color: #00b2ee; 
content: ''; 
vertical-align: middle; 
display: inline-block; 
position: relative; 
right: 5px; 
} 

/* Sub Menu 
----------------------------------------------------- */ 
ul#nav ul { 
position: absolute; 
top: 100%; 
left: 0; 
background: #c7c7c7; 
min-width: 100%; 


border-radius: 5px 5px 7px 7px; 

/* for transition effects */ 
opacity: 0; 
filter: alpha(opacity=0); 

-webkit-transition: opacity .25s ease .1s; 
-moz-transition: opacity .25s ease .1s; 
-o-transition: opacity .25s ease .1s; 
-ms-transition: opacity .25s ease .1s; 
transition: opacity .25s ease .1s; 
} 

/* Third level sub menu 
ul#nav ul ul { 
position: absolute; 
top: 0; 
left: 100%; 

border-radius: 0 3px 3px 3px; 
} 
*/ 

ul#nav ul li { 
padding: 0; 
display: block; 
text-align: left; 

/* for transition effects */ 
height: 0; 
overflow: hidden; 

-webkit-transition: height .25s ease .1s; 
-moz-transition: height .25s ease .1s; 
-o-transition: height .25s ease .1s; 
-ms-transition: height .25s ease .1s; 
transition: height .25s ease .1s; 
} 

/*On Hover */ 
ul#nav li:hover > ul { 
opacity: 1; filter: alpha(opacity=100); 
} 
ul#nav li:hover > ul li { 
height: 42px; 
overflow: visible; 
border-bottom: 1px solid #26272C; 
color: #ffffff; 
} 
ul#nav li:hover > ul li:last-child { border: none; } 

/* Sub Menu Anchor links */ 
ul#nav ul li a { 
padding: 6px 15px; 
margin: 0; 
white-space: nowrap; 
font-size: 13px; 
} 

如果你想使用一些不同的颜色,而徘徊在下拉文本链接,你需要在CSS单独使用此代码: -

ul#nav li:hover > a {color:your color name or color code} 
+0

太棒了!我尝试使用它,但在错误的部分使用它。我像你说的那样把它放进去,它现在正在工作!感谢您的帮助! – epalm18

+0

@ epalm18不客气!很高兴我可以帮忙:) –

相关问题