我有一个<ol>
列表,我添加了颜色。这工作正常。但是当我添加一个有2个标签的div时,悬停效果就不适用了。
在我的代码中,第二个<li>
没有发生悬停。
HTML:
<div class="test">
<ol>
<a href="#"><li><div><span>test 1</span><p>Mvdshe</p></div></li></a>
<a href="#"><li><div><span>test 12</span><p>sdgmksgb</p></div>
<div class="icons"><a href="#" class="play"></a><span class="dividr"></span><a href="#" class="suffle"></a></div></li></a>
<a href="#"><li><div><span>test 11</span><p>Name dgdg</p></div></li></a>
</ol>
</div>
CSS:
.test{ position:relative; height:auto; width:100%}
.test ol{margin:0; padding:0; font:normal 30px 'SegoeWPLight', Verdana, Geneva, sans-serif; color:#afafaf; text-align:left; list-style:none; counter-reset: listCounter;}
.test ol li{vertical-align:middle; padding:10px 20px; border-bottom:#d4d4d4 solid 1px; border-top:#fff solid 1px; counter-increment: listCounter;}
.testol li:before { content: counter(listCounter) " "; width:30px; margin-right:15px; display: inline-block; text-align: right; }
.test ol li span{vertical-align:middle; display:block; color:#008fcd; font:normal 18px 'SegoeWPLight', Verdana, Geneva, sans-serif;}
.test ol li p{vertical-align:middle; display:block; margin:0; padding:0; font:normal 14px 'SegoeWPLight', Verdana, Geneva, sans-serif; color:#797979;}
.test ol li img{vertical-align:middle; padding-left:10px }
.test ol li div{ display:inline-block; margin-left:25px; vertical-align:middle; }
.test ol a{ text-decoration:none; font:normal 30px 'SegoeWPLight', Verdana, Geneva, sans-serif; color:#afafaf;}
.test ol a:hover li{ background-color:#f4f4f4}
.test ol a.mus_active li{ background-color:#f4f4f4}
.icons{display:inline-block; float:right; vertical-align:middle; width:auto; margin-top:20px}
.play{background:url(http://www.timeshighereducation.co.uk/magazine/graphics/search_icon_big.gif) no-repeat left; width:25px; height:25px; background-size:15px; display:inline-block !important; }
.suffle{background:url(../images/suffle.png) no-repeat left; width:25px; height:25px; display:inline-block !important}
.dividr{background:url(http://www.timeshighereducation.co.uk/magazine/graphics/search_icon_big.gif) no-repeat left; width:3px; height:28px; display:inline-block !important; margin:0 8px 10px 0}
答案 0 :(得分:1)
试试这个 http://jsfiddle.net/bFVGr/2/
.test ol li { vertical-align:middle; border-bottom:#d4d4d4 solid 1px; border-top:#fff solid 1px; counter-increment: listCounter; }
.test ol li > a{display:block; padding:10px 20px;}
.test ol li > a:hover { background-color:#f4f4f4 }
答案 1 :(得分:0)
将LI放在锚标记内是错误的。写得像这样:
<ol>
<li><a></a></li>
<li><a></a></li>
</ol>
在FF&amp; chrome你的代码渲染如下:
<ol>
<a href="#"><li><div><span>test 1</span><p>Mvdshe</p></div></li></a>
<a href="#"></a><li><a href="#"><div><span>test 12</span><p>sdgmksgb</p></div>
</a><div class="icons"><a href="#"></a><a class="play" href="#"></a><span class="dividr"></span><a class="suffle" href="#"></a></div></li>
<a href="#"><li><div><span>test 11</span><p>Name dgdg</p></div></li></a>
</ol>
答案 2 :(得分:0)
如果您不想按照其他人的建议更改列表结构,那么您可以做的就是将第二个列表放在div中并应用相同的效果;)
<div id = "special">
<a href="#">
<li>
<div>
<span>test 12</span><p>sdgmksgb</p>
</div>
<div class="icons">
<a href="#" class="play"></a><span class="dividr"></span>
<a href="#"class="suffle"></a>
</div>
</li>
</a>
</div>
和
.test #special:hover{background-color:#f4f4f4}
修改强>
为了使我认为你想要的整个div可点击,你可以做到
.test #special a{display:block}
或查看this