考虑:
ul {
list-style-position: inside;
}
ul li {
border-radius: 7px;
line-height: 21px;
padding: 0 9px;
letter-spacing: 0.5px;
}
ul li a {
color: #555;
}
ul li:hover {
background: #0099cc;
color: white;
}
ul li a:hover {
color: white;
}
<div class='titlewrap'>
<ul>
<li class='title'><a href='view.php?id=1' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=2' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=3' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=4' target='_blank'>lorem ipsum</a></li>
</ul>
</div>
悬停时,li a
颜色会变为白色,但当我将指针移到a
之外且仍在li
之内时 - 颜色再次为#555
。
答案 0 :(得分:3)
目前,您使用ul li a
设置颜色,其特异性高于ul li:hover
。
我相信你所寻找的是ul li:hover a
而不是ul li a:hover
。
ul {
list-style-position: inside;
}
ul li {
border-radius: 7px;
line-height: 21px;
padding: 0 9px;
letter-spacing: 0.5px;
}
ul li a {
color: #555;
}
ul li:hover {
background: #0099cc;
color: white;
}
ul li:hover a {
color: white;
}
&#13;
<div class='titlewrap'>
<ul>
<li class='title'><a href='view.php?id=1' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=2' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=3' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=4' target='_blank'>lorem ipsum</a></li>
</ul>
</div>
&#13;
答案 1 :(得分:2)
改为使用
ul li:hover a {
color: white;
}
ul {
list-style-position: inside;
}
ul li {
border-radius: 7px;
line-height: 21px;
padding: 0 9px;
letter-spacing: 0.5px;
}
ul li a {
color: #555;
}
ul li:hover {
background: #0099cc;
color: white;
}
ul li:hover a {
color: white;
}
&#13;
<div class='titlewrap'>
<ul>
<li class='title'><a href='view.php?id=1' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=2' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=3' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=4' target='_blank'>lorem ipsum</a></li>
</ul>
</div>
&#13;
答案 2 :(得分:0)
ul li a
比ul li:hover
更具体
而是嵌套的锚标记从其包含的列表项标记继承其color
。
ul li a {
color: inherit;
}
ul {
list-style-position: inside;
}
ul li {
border-radius: 7px;
line-height: 21px;
padding: 0 9px;
letter-spacing: 0.5px;
}
ul li a {
color: inherit;
}
ul li:hover {
background: #0099cc;
color: white;
}
ul li a:hover {
color: white;
}
<div class='titlewrap'>
<ul>
<li class='title'><a href='view.php?id=1' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=2' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=3' target='_blank'>lorem ipsum</a></li>
<li class='title'><a href='view.php?id=4' target='_blank'>lorem ipsum</a></li>
</ul>
</div>
答案 3 :(得分:0)
在CSS中添加此行:
ul li:hover a{
color: white;
}