CSS图标&精灵&导航

时间:2012-05-26 06:37:18

标签: css icons css-sprites sprite

我正在创建一个小导航系统,虽然我会尝试一下CSS精灵......

我的HTML如下

<ul>
 <li><i class="collections"></i><a href="collections.html">My Collections</a></li>
 <li><i class="everything"></i><a href="everything.html">Everything</a></li>
 <li><i class="social"></i><a href="social.html">Social</a></li>
 <li><i class="news"></i><a href="news.html">News</a></li>
 <li><i class="shopping"></i><a href="shopping.html">Shopping</a></li>
 <li><i class="financial"></i><a href="financial">Financial</a></li>
 <li><i class="travel"></i><a href="travel">Travel</a></li>
 <li><i class="entertainment"></i><a href="entertainment">Entertainment</a></li>        
</ul>

我正在使用图标(因为Twitter Bootstrap会这样做)。

我的CSS是

i { display: block;  background-image: url('../img/sprites.png'); background-repeat: no-repeat; background-position: top left; }

.entertainment:hover{ background-position: -32px 0; width: 16px; height: 11px; } 
.entertainment{ background-position: -58px 0; width: 16px; height: 11px; } 
.everything:hover{ background-position: -84px 0; width: 16px; height: 15px; } 
.everything{ background-position: -110px 0; width: 16px; height: 15px; } 
.collections:hover{ background-position: -136px 0; width: 16px; height: 16px; } 
.collections{ background-position: -162px 0; width: 16px; height: 16px; } 
.news:hover{ background-position: -188px 0; width: 16px; height: 16px; } 
.news{ background-position: -214px 0; width: 16px; height: 16px; } 
.shopping:hover{ background-position: -240px 0; width: 16px; height: 16px; } 
.shopping{ background-position: -266px 0; width: 16px; height: 16px; } 
.social:hover{ background-position: -313px 0; width: 16px; height: 16px; } 
.social{ background-position: -339px 0; width: 16px; height: 16px; } 
.travel:hover{ background-position: -365px 0; width: 16px; height: 16px; } 
.travel{ background-position: -391px 0; width: 16px; height: 16px; } 
.financial:hover{ background-position: -417px 0; width: 16px; height: 12px; } 
.financial{ background-position: -443px 0; width: 16px; height: 12px; } 

我遇到的问题是我希望悬停时更改图标,但只能在<i>元素上进行更改。我在<li><a>中发生了一些与之相冲突的事情。

有什么想法吗?

JS小提琴 - http://jsfiddle.net/sturobson/5t6XE/

1 个答案:

答案 0 :(得分:1)

您有:hover设置在<i>标记上。尝试使用类似的东西:

li:hover .financial{ // CSS rules.... }