1

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?

Community
  • 1
  • 1
Kaivosukeltaja
  • 15,541
  • 4
  • 40
  • 70

3 Answers3

0

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.

t.niese
  • 39,256
  • 9
  • 74
  • 101
0

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.

Community
  • 1
  • 1
jamesplease
  • 12,547
  • 6
  • 47
  • 73
0

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.

Homam
  • 707
  • 2
  • 9
  • 20