7

I have an html td element with text inside. I want it so you can hover over that element, and display a textbox on top of the active page/element explaining what that td tag's content means. Some kind of elaboration. Like the <abbr> tag.

Can this be done in CSS or Javascript?

3 Answers 3

11

This is possible with CSS, also with javascript. Create a table with an element:

<table>
<tr><td>
    <a href="#">Info
        <div class="tooltipcontainer">
            <div class="tooltip">Here some info</div>
        </div>
    </a>
</td></tr>
</table>

CSS:

/* Container is necessary because td cannot be positioned relative */
td .tooltipcontainer {
    position: relative;
}
td .tooltip {
    display: none;
    position: absolute;
    /* More positioning, heigh, width, etc */
}
td a:hover .tooltip {
    display: block;
}

When you hover over 'Info' it will show the text in the div with class='tooltip'. JavaScript (for example any jQuery tooltip plugin) has solutions with more options.

2
  • This would be better for usability tbh Mar 22, 2012 at 12:25
  • Thank you. This was the kind of CSS solution I was looking for. I do think however the Javascript solution has more benefits. Mar 22, 2012 at 18:59
3

Example markup..

<td id="1">..</td>
<td id="2">..</td>
<td id="thisiswhatiwanttohaveahover"><div class="tooltip hidden"></div></td>

CSS Style

.visible {
  display:block;
}

.hidden {
  display:none;
}

you can

$('#thisiswhatiwanttohaveahover').hover(function() {
  if ($(this + ' .tooltip').hasClass('hidden')) {
    $(this + ' .tooltip').removeClass('hidden');
    $(this + ' .tooltip').addClass('visible');
  }
  if ($(this + ' .tooltip').hasClass('visible')) {
    $(this + ' .tooltip').removeClass('visible');
    $(this + ' .tooltip').addClass('hidden');
  }
});

hope this helps..

0
2

I've used Tooltip JS before. It worked really well and I think it'd be beneficial to you.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.