liveBook · Manning

Image-caption class

As explained in Web Design Playground, Second Edition

The image-caption class is a CSS class assigned to a caption layer displayed over a thumbnail image.

An image-caption class styles a caption layer that sits over a thumbnail instead of taking up space below it. The thumbnail container uses relative positioning; the caption uses absolute positioning, matching dimensions, and top-left placement. Its dark, slightly transparent background preserves a glimpse of the image while keeping the text readable. section 15.8

Reveal the caption on hover

Give the caption a vertical flex layout, align its contents to the bottom, and hide it with opacity: 0. Then the hover rule changes opacity to 1. Hovering over the thumbnail makes the caption appear with a satisfying little reveal. section 15.8

.image-caption {
    display: flex;                                 #1
    flex-direction: column;                        #1
    justify-content: flex-end;                     #1
    position: absolute;                            #2
    left: 0;                                       #2
    top: 0;                                        #2
    width: 300px;                                  #3
    height: 200px;                                 #3
    background-color: rgba(32, 32, 32, 0.75);      #4
    color: #ecd078;
    opacity: 0;                                    #5
}

Inspect the complete overlay styling, including absolute positioning, dimensions, translucent background, text color, and default opacity. section 15.8

How Web Design Playground, Second Edition covers it

How deep it goes
Explains the overlay layout and hover reveal, but stops short of discussing accessibility or advanced animation.
Examples
Uses a photo-gallery thumbnail with a title, descriptive caption, translucent overlay, and hover-triggered visibility.
What it assumes
Assumes basic HTML and CSS familiarity while introducing relative and absolute positioning through a concrete gallery example.
What you can do after
Apply it via CSS to build thumbnail captions that appear when users hover over images.
How it connects
Connects CSS positioning, flexbox, opacity, pseudo-classes, and thumbnail layouts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.