当target ="_ blank"时,链接保持其悬停属性. [英] Link stays on its hover property when target="_blank"
问题描述
每当我设置一个链接以打开一个新窗口并返回到前一个窗口时,为其设置的悬停属性就会保留,但是当我将鼠标移回到该窗口时,它将恢复为正常.如何不使用Javascript来解决此问题?
Whenever I set a link to open up into a new window and return to the previous one the hover properties set for it stick but when I mouse back in to the window it changes back to normal. How can I fix this without using Javascript?
HTML:
<a href="google.com" target="_blank">Google</a>
CSS:
a:link, a:visited, a:active {color: blue;}
a:hover {color: red;}
JSFiddle
推荐答案
我也遇到了类似的问题,该链接的样式为按钮,当单击操作打开一个新窗口时,该按钮保持其悬停字体颜色.问题在于,链接将保持焦点(保持悬停样式),直到您单击其他内容为止,这显然是可访问性.我想出的解决方法是添加:focus样式和:focus:hover样式以模仿常规的a和a:hover样式.
I had a similar issue with a link styled as a button that was keeping its hover font color when the click action was to open a new window. The issue is that the link retains focus (which holds the hover style) until you click on something else, which is apparently an accessibility thing. The workaround I came up with is to add a :focus style and a :focus:hover style to mimic the regular a and a:hover styles.
a, a:focus { color: blue }
a:hover, a:focus:hover { color: white }
这篇关于当target ="_ blank"时,链接保持其悬停属性.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!