Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link stays on its hover property when target="_blank"

Tags:

html

css

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

http://jsfiddle.net/5EXFB/

like image 591
Carl Edwards Avatar asked Jun 30 '14 17:06

Carl Edwards


People also ask

How do I turn off hover link?

To remove the CSS hover effect from a specific element, you can set the pointer-events property of the element (the hover behavior of which you want to disable) to “none”.

What does the target _blank attribute do?

A target attribute with the value of “_blank” opens the linked document in a new window or tab. A target attribute with the value of “_self” opens the linked document in the same frame as it was clicked (this is the default and usually does not need to be specified).

What should target _blank do when included in a link tag?

a target=”_blank” Open in New Browser Tab (or Window) The target attribute specifies where the linked document will open when the link is clicked. The default is the current window. If target="_blank" , the linked document will open in a new tab or (on older browsers) a new window.

Can you add target _blank to URL?

You can use the target="_blank" attribute if you want your users to click on a link that opens up a new browser tab. The target="_blank" attribute is used inside the opening anchor tag like this.


1 Answers

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 }
like image 78
Richard Avatar answered Oct 28 '22 01:10

Richard