I've been experimenting with creating a tooltip that appears when hovering over an <a>
tag and displays a <div>
from another location
For example:
<p>
blah blah <a class="tooltiphover">hover me</a> blah blah
</p>
<div class="tooltip">
<!-- tooltip info code goes here -->
</div>
However, all the tutorials and resources I have come across focus on using child elements which can clutter the code or require the use of extra <div>
tags that may disrupt the visual appearance of the site
Another common approach is exemplified by:
<div class="tooltiphover">Hover me</div>
<span class="tooltip">Tooltip stuff</span>
</div>
This becomes problematic especially when dealing with CSS selectors like .tooltiphover:hover .tooltip
.
Is there a way in CSS to style both elements simultaneously without one being a child of the other? Using a comma or plus sign doesn't seem to achieve the desired effect.
Thank you for your help.
EDIT: To simplify, how can I make the div display in front of everything and beside the <a>
tag like a proper tooltip? I might resort to using JavaScript for handling the mouseover
event. It seems easier than struggling with CSS and HTML due to the confusing array of tooltip tutorials available online 😅
What would be the appropriate CSS code for achieving this?