我正在尝试在span
内设置一个文本,该文本位于焦点上的锚标记内。
在焦点上,文字应该会收到underline
。重点需要通过标签来实现。
但它不起作用。
有人可以看看,让我知道缺少什么
body > div.afterLink > a > span:focus {
border-bottom: 2px solid green;
}

<div class="beforeLink">
<span tabIndex=-1>Go to Google</span>
</div>
<div class="titleLink">
<a class="download" target="_blank" href="www.google.com" title="Click here">
<span>Go to Google</span>
</a>
</div>
<div class="afterLink">
<a class="download" target="_blank" href="www.google.com" title="Click here">
<span>Go to Google</span>
</a>
</div>
&#13;
答案 0 :(得分:2)
使用:focus
中的a
代替
div.afterLink > a:focus > span {
border-bottom: 10px solid green
}
&#13;
<div class="beforeLink">
<span tabIndex=-1>Go to Google</span>
</div>
<div class="titleLink">
<a class="download" target="_blank" href="www.google.com" title="Click here">
<span>Go to Google</span>
</a>
</div>
<div class="afterLink">
<a class="download" target="_blank" href="www.google.com" title="Click here">
<span>Go to Google</span>
</a>
</div>
&#13;
答案 1 :(得分:1)
无法聚焦跨度元素(除非它们具有tabindex属性)。将焦点选择器放在锚点上:
body > div.afterLink > a:focus > span {
border-bottom: 2px solid green;
}
&#13;
<div class="beforeLink">
<span tabIndex=-1>Go to Google</span>
</div>
<div class="titleLink">
<a class="download" target="_blank" href="www.google.com" title="Click here">
<span>Go to Google</span>
</a>
</div>
<div class="afterLink">
<a class="download" target="_blank" href="www.google.com" title="Click here">
<span>Go to Google</span>
</a>
</div>
&#13;