I know it's possible to get an a:hover color without hovering on the element, but what about it's width and height? If the link's size is auto
, it can't be read from the stylesheets. I'm intending to do some experimental trickery with links that hover to bold. Is my only option binding to the hover event?

- 1
- 1

- 15,541
- 4
- 40
- 70
-
2You can get with javascript or jQuery – Morpheus Jan 11 '13 at 15:12
3 Answers
you could solve it in a similar way like with the colors. if you extract all informations from the stylesheet that would influence the width. and apply it to a temporary element with the same content of the link. then you could calculate the width.
if you create the stylesheet yourself it would be easier if you create a css rule like this.
a:hover, a.hover {}
and then temporary add the class .hover to the link and calculate its size.

- 39,256
- 9
- 74
- 101
I'd suggest using this method, but changing it up to add the styling to the span
so that it matches the styling of your a:hover
.

- 1
- 1

- 12,547
- 6
- 47
- 73
Personally if there is no matter of performance leaks,
i can suggest a simpler way, use jquery .trigger()
to trigger a mouseover
event on the desired element and then take its width, it can give you a more practical size than the other ways. although you can use it async to other scripts and functions for not affecting your page.

- 707
- 2
- 9
- 20