I have a CSS only tooltip which loads a span
as a tooltip when you hover
the link. However this is positioned with CSS but if the link is near to the top of a page or side then the tooltip goes off the side/top of the page.
Is there a way with css to make this change or will I have to rely on JS? I have started to try to put something together with jQuery but would rather use CSS if possible.
JS fiddle at https://jsfiddle.net/gtoprh21/12/
Snippet:
Unfortunately, if you want to keep your tooltip good positioning, it isn't possible using only CSS.
Script solutions
But, as you're already using some script, I suggest you this solution:
position: absolute
to position the .ktooltiptext
accordingly to .ref
,.getBoundingClientRect()
method to easily get the position and size of the tooltip,window
,Snippet with only native JavaScript (avoiding jQuery, document will be lighter.)