Home >Web Front-end >CSS Tutorial >How Can I Display Text on Image Hover Without Using Tooltips?
Displaying Text on Image Hover Without Tooltips
In web design, it's often desirable to display additional information when the user hovers over an image. While tooltips are a popular solution, they may not always provide the desired aesthetic or functionality. This article explores how to achieve this effect using pure CSS or jQuery.
Using CSS:
CSS3 introduces the :hover pseudoelement, which allows for styling when the mouse hovers over an element. In this case, the hover effect will be applied to the image.
HTML:
<div>
CSS:
#wrapper .text { position: relative; bottom: 30px; left: 0px; visibility: hidden; } #wrapper:hover .text { visibility: visible; }
This CSS places the text caption at the bottom-left corner of the image and hides it until the mouse hovers over the image.
Using jQuery:
jQuery can also be used to achieve the same effect. This method may provide more flexibility for more complex scenarios.
HTML:
Same as before.
CSS:
#wrapper p { position: relative; bottom: 30px; left: 0px; visibility: hidden; }
jQuery:
$('.hover').mouseover(function() { $('.text').css("visibility", "visible"); }); $('.hover').mouseout(function() { $('.text').css("visibility", "hidden"); });
This jQuery script binds mouseover and mouseout events to the image element and toggles the visibility of the caption.
Regardless of the method used, by utilizing CSS or jQuery, it's possible to create a custom hover effect that displays additional information on an image without the use of tooltips.
The above is the detailed content of How Can I Display Text on Image Hover Without Using Tooltips?. For more information, please follow other related articles on the PHP Chinese website!