OBJECTIVE: A basic pop-up image tooltip will be created by hiding and showing a div tag that has been styled and positioned
using the hover pseudo-class.
First let's write code for a basic unstyled layout by creating:
<div>
<a href="#">
<img src="images/debra_samson.jpg"
alt="Debra Samson" border="0" /> </a>
<p>Info for tooltip goes here...Info for tooltip goes here...Info for tooltip goes here...Info for tooltip
goes here...</p>
<h2>Image Caption</h2>
</div>
Info for tooltip goes here...Info for tooltip goes here...Info for tooltip goes here...Info for tooltip goes here...
NOTE: An optional
Also the href attribute was set to "#". If you need to have it link to a url change it to a relative or absolute link (i.e., href="mynewpage.html").
Style the following element containers:
div {width:100px; border:1px solid blue; padding:5px;}
p, h2 {font-size:.8em; font-family:Arial, sans-serif; margin:0;}
p {width:90px;border:1px solid black; padding:.3em;background-color:#FF6;}
Position the tooltip on the right side of the image by setting:
This will take the tooltip out of the normal flow of the document and position it absolutely but relative to its parent container.
NOTE: Changes in existing code highlighted in bold
div {position:relative; width:100px; border:1px solid blue; padding:5px;}
p, h2 {font-size:.8em; font-family:Arial, sans-serif; margin:0;}
p {position:absolute; top:7px; left:110px; width:90px;border:1px solid black; padding:.3em;background-color:#FF6;}
Info for tooltip goes here...Info for tooltip goes here...Info for tooltip goes here...Info for tooltip goes here...
Hide and show tooltip container by setting the display property and the hover pseudo-class
div p {display:none;}
div:hover p, p:hover{display:block;}
Must preview in a browser to see how tooltip works: If the mouse hovers over the image_container, then display the tooltip.
Also, if the mouse hovers over the tooltip once it has been displayed by hovering over the image then continue to display it.
Create a image highlight when cursor is over it by:
Must preview in a browser to see how tooltip works: When the mouse is hovered over the image a 1 pixel red border will
be displayed and the image will getting smaller. When the mouse is not over the image, border will be removed and image will return to original size.
NOTE: If you do not want the image to "animate", change the border property from 0 to 1 in the second <p> tag and delete the height and
width properties in the css rule: img:hover.
IMPORTANT NOTE: To use the tool tip in a real world example using multiple images:
div.photo_gallery {position:relative; width:100px; border:1px solid blue; padding:5px;}
div.photo_gallery p, div.photo_gallery h2 {font-size:.8em; font-family:Arial, sans-serif; margin:0;}
div.photo_gallery p {position:absolute; top:7px; left:110px; width:90px;border:1px solid black; padding:.3em;background-color:#FF6;}
div.photo_gallery p {display:none; }
div.photo_gallery:hover p, div.photo_gallery p:hover{display:block;}
div.photo_gallery img:hover {border: 1px solid red;height:98px; width:98px;}
div.photo_gallery img {border:0;}
Info for Debra Samson goes here...Info for Debra Samson goes here...Info for Debra Samson goes here...
Info for Bob Anderson goes here...Info for Bob Anderson goes here...Info for Bob Anderson goes here...
Info for Carol Green goes here...Info for Carol Green goes here...Info for Carol Green goes here...
If a viewer is using an older version of Internet Explorer...