我想在CSS(或任何其他伪选择器)中结合:after使用:hover。我基本上有一个列表,并且selected该类的项目具有使用施加的箭头形状:after。我希望对悬停的对象也是如此,但不能完全使其正常工作。继承人代码
:after
:hover
selected
#alertlist { list-style:none; width: 250px; } #alertlist li { padding: 5px 10px; border-bottom: 1px solid #e9e9e9; position:relative; } #alertlist li.selected, #alertlist li:hover { color: #f0f0f0; background-color: #303030; } #alertlist li.selected:after { position:absolute; top: 0; right:-10px; bottom:0; border-top: 10px solid transparent; border-bottom: 10px solid transparent; border-left: 10px solid #303030; content: ""; } <ul id="alertlist"> <li>Alert 123</li> <li class="selected">Alert 123</li> <li>Alert 123</li> </ul>
只需:after以与#alertlist li:hover选择器相同的方式将其追加到选择#alertlist li.selected器即可:
#alertlist li:hover
#alertlist li.selected
#alertlist li.selected:after, #alertlist li:hover:after { position:absolute; top: 0; right:-10px; bottom:0; border-top: 10px solid transparent; border-bottom: 10px solid transparent; border-left: 10px solid #303030; content: ""; }