Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textbox 'popup' display on mouseover/hover for CSS/Javascript

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?

like image 412
DextrousDave Avatar asked Mar 22 '12 12:03

DextrousDave


People also ask

How do you put hover over text?

Using <SPAN> Tag What you'll want to do is enclose whatever text you'd like to have a mouseover in span tags. those look like this: <span>This is the text I want to have a mousover</span>. You can do this by either finding the text you want in the HTML editor, or by typing it yourself.

How do you make a hover box in CSS?

The :hover CSS pseudo-class matches when the user interacts with an element with a pointing device, but does not necessarily activate it. It is generally triggered when the user hovers over an element with the cursor (mouse pointer).


2 Answers

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.

like image 70
Frank van Wijk Avatar answered Nov 02 '22 16:11

Frank van Wijk


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..

like image 34
Teody C. Seguin Avatar answered Nov 02 '22 15:11

Teody C. Seguin