Flexible galleries with CSS: grid

Works either with images in the <img>tag, or in a div where the image is set with the background-image property (or even both).
Because the gallery grid automatically adapts to the width of the container, it is much easier to make the gallery responsive for mobile web browsers.

CSS
HTML

Example

Resize the container by dragging the slider to the left and see what happens. The sample code also shows you how to link the thumbnails so that you can view them at full size.
(The slider is only part of the demo to demonstrate how the gallery behaves at different resolutions and container widths)