#menu {float:left; margin:0; padding:0; list-style-type:none; width:100%; border:1px solid #BBBBBB; background-color:#FFFFFF;}
#menu li {display:list-item; float:left;}
#menu a:link,a:visited {border-right:1px solid #BBBBBB; display:block; float:left; padding:10px 15px; color:#AAAAAA; text-decoration:none; font-weight:bold; -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear;}
#menu a:hover,a:active {background-color:#0096FF; color:#FFFFFF; -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear;}
这是HTML:
<div id='header'>
<a href='index.html'><img src='logo.png' /></a>
</div>
<ul id='menu'>
<li><a href='index2.html'>HOME</a></li>
<li><a href='index.html'>FORUM</a></li>
</ul>
问题是,我在UL之前有另一个链接,它也获得了这些属性。如何才能使UL内部的链接获得这些属性而不是之前的链接(在UL之外)。
答案 0 :(得分:3)
更改此
#menu a:link,#menu a:visited {border-right:1px solid #BBBBBB; display:block; float:left; padding:10px 15px; color:#AAAAAA; text-decoration:none; font-weight:bold; -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear;}
#menu a:hover,#menu a:active {background-color:#0096FF; color:#FFFFFF; -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear;}
你忘了把#menu放在a:visited和a:active
之前