Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pop up an image in a separate div on mouse-over using CSS only?

Tags:

css

xhtml

popup

I have a small gallery of thumbnails. When I place my mouse pointer over a thumbnail image I'd like to have a full size image pop up in a div in the top right of the screen. I've seen this done using just CSS and I'd like to go down that route rather than use javascript if possible.

like image 216
user18748 Avatar asked Sep 20 '08 15:09

user18748


People also ask

How do you make a div appear when hover over another div?

We can apply an adjacent sibling CSS selector property to the <a> tag that will display the hidden div element's content while hovering over it. The Adjacent sibling selector is a CSS Combinators, used to select the element that is adjacent or the element that is next to the specified selector tag.

How do you hover an image in CSS?

Answer: Use the CSS background-image property You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.

How do I make an image go in front of another in CSS?

Use the CSS z-index property. Elements with a greater z-index value are positioned in front of elements with smaller z-index values.

How can I display text on image when the cursor is hovered over it in HTML?

First, start with designing HTML layout. Creating 3 <div class='content_img'> parent elements that hold a <img > and a <div> elements that are using to show Additional text when hovering over the image.


2 Answers

Pure CSS Popups2, from the same site that brings us Complexspiral. Note that this example is using actual navigational links as the rolled-over element. If you don't want that, it may cause some stickiness regarding versions of IE.

The basic technique is to stick each image inside a link tag with an actual href (Otherwise some IE versions will neglect :hover)

<a href="#">Text <img class="popup" src="pic.gif" /></a>

and position it cleverly using absolute position. Hide the image initially

a img.popup { display: none }

and then on the link rollover, set it up to appear.

a:hover img.popup { display: block }

That's the basic technique, but there are always going to be major positioning limitations since the image tag dwells inside the link tag. See the link for details; he uses something a little more tricky than display: none to hide the image.

like image 126
2 revs Avatar answered Sep 21 '22 17:09

2 revs


CSS Playground uses pure CSS for this type of thing, one of the demos is surely to help you and as it's all CSS just view source to learn - you probably want to use the :hover pseudo class but there are limitations to it depending on your browser targeting.

like image 40
Paul Shannon Avatar answered Sep 22 '22 17:09

Paul Shannon