简体   繁体   English

改变背景颜色悬停在不同的li a

[英]Changing background color hovering over different li a

I got my navigation bar to work nicely but I need to have different colors in the backgrounds of each element. 我让我的导航栏很好地工作但我需要在每个元素的背景中有不同的颜色。 I tried giving them ID's and using it in CSS but it doesn't work. 我尝试给他们ID并在CSS中使用它,但它不起作用。 The "info day"should be firebrick(red) but "course"and "locations" should be two different colors. “信息日”应该是耐火砖(红色),但“路线”和“位置”应该是两种不同的颜色。 Can anyone one help me out? 任何人都可以帮助我吗?

 .menuUl { list-style-type: none; margin: 0; padding: 0; overflow: hidden; border-left: none; border-right: none; } .menuLi { float: left; border: none; } li a { display: block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } li a:hover { background-color: firebrick; border-radius: 5px; } 
 <ul class="menuUl"> <li class="menuLi" id="courses"><a class="active" href="EindOpdracht.html">COURSES</a> </li> <li class="menuLi" id="infoDay"><a href="">INFO DAY</a> </li> <li class="menuLi" id="locations"><a href="Location.html">LOCATIONS</a> </li> </ul> 

Hope this helpful: 希望这有用:

 .menuUl{ list-style-type: none; margin: 0; padding: 0; overflow: hidden; border-left: none; border-right: none; } .menuLi{ float: left; border: none; } li a { display: block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } li:nth-child(1) a:hover { background-color: blue; border-radius: 5px; } li:nth-child(2) a:hover { background-color: firebrick; border-radius: 5px; } li:nth-child(3) a:hover { background-color: black; border-radius: 5px; } 
 <ul class="menuUl"> <li class="menuLi" id="courses"><a class="active" href="EindOpdracht.html">COURSES</a></li> <li class="menuLi" id="infoDay"><a href="">INFO DAY</a></li> <li class="menuLi" id="locations"><a href="Location.html">LOCATIONS</a></li> </ul> 

I change their font-color for visibility in the snippet-demo but the main idea is to use them like this li#infoDay a:hover . 我在片段演示中更改了字体颜色的可见性,但主要的想法就是使用它们像li#infoDay a:hover Its specific to id's and changing their order wont affect the css 它特定于id并改变它们的顺序不会影响css

 .menuUl{ list-style-type: none; margin: 0; padding: 0; overflow: hidden; border-left: none; border-right: none; } .menuLi{ float: left; border: none; } li a { display: block; color: black; text-align: center; padding: 14px 16px; text-decoration: none; } li a:hover { border-radius: 5px; } li#courses a:hover{ background-color: blue; } li#locations a:hover{ background-color: green; } li#infoDay a:hover{ background-color: firebrick; } 
 <div> <ul class="menuUl"> <li class="menuLi" id="courses"><a class="active" href="EindOpdracht.html">COURSES</a></li> <li class="menuLi" id="infoDay"><a href="">INFO DAY</a></li> <li class="menuLi" id="locations"><a href="Location.html">LOCATIONS</a></li> </ul> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM