Pro CSS3 Animation

(Tuis.) #1
Chapter 3 ■ CSS3 tranSitionS for imageS

:target


The use of :target may be the most effective pseudo-selector in this instance, although it does require some
addition to your markup. :target derives from the use of traditional “anchors” of id values, detecting clicks on
elements linked to those ids.
Your HTML changes to that shown in Listing 3-13.


Listing 3-13. HTML for an Image Gallery with :target



Under normal circumstances a link to an anchor would force the page to scroll to the location of the id
with a visual jump; that is avoided in this case because the dd elements are absolutely positioned near the top
of the page.
Only one line of the CSS requires modification. Your :hover declaration changes as shown in Listing 3-14.


Listing 3-14. CSS for an Image Gallery with :target


dd#jatropha:target, dd#veins:target, dd#cascada:target { opacity: 1; }


This approach also has the advantage of modifying the URL, meaning that users may be led to particular
images through the use of links with appended ids. For example, http://www.yourdomain.com/gallery.html#cascada
would bring up the last image in the gallery automatically.


Simple Popup Image Captions


It is also possible to display the caption of an image on mouseover, either in a gallery or as part of a user interface.
The ideal markup for this is either a definition list, as in the previous example, or a

and
,
which are the elements you’ll use for this next example, as shown in Figure 3-3 and Listing 3-15. (I’m using
photographs by Bradley Davis (www.flickr.com/photos/backpackphotography/244716694/) and Wolfgang
Staudt (www.flickr.com/photos/wolfgangstaudt/). If you decide to use your own images, make sure they are of
a similar size.)

Free download pdf