<!DOCTYPE html> <html> <head> <style> div.gallery { border: 2px solid purple; } div.gallery:hover { border: 2px solid purple; } div.gallery img { width: 100%; height: auto; } div.desc { padding: 15px; text-align: center; } * { box-sizing: border-box; } .responsive { padding: 0 6px; float: left; width: 24.99999%; } @media only screen and (max-width: 700px) { .responsive { width: 49.99999%; margin: 6px 0; } } @media only screen and (max-width: 500px) { .responsive { width: 100%; } } .clearfix:after { content: ""; display: table; clear: both; } </style> </head> <body> <h2>Responsive Image Gallery</h2> <h4>Resize the browser window to see the effect.</h4> <div class="responsive"> <div class="gallery"> <a target="_blank" href="examples/resources/dog.jpg"> <img src="examples/resources/dog.jpg" alt="Cinque Terre" width="600" height="400"> </a> <div class="desc">Add a description of the image here</div> </div> </div> <div class="responsive"> <div class="gallery"> <a target="_blank" href="examples/resources/tajmahal.png"> <img src="examples/resources/tajmahal.png" alt="Forest" width="600" height="400"> </a> <div class="desc">Add a description of the image here</div> </div> </div> <div class="responsive"> <div class="gallery"> <a target="_blank" href="examples/resources/css3-3d7.png"> <img src="examples/resources/css3-3d7.png" alt="Northern Lights" width="600" height="400"> </a> <div class="desc">Add a description of the image here</div> </div> </div> <div class="responsive"> <div class="gallery"> <a target="_blank" href="examples/resources/diamond.jpg"> <img src="examples/resources/diamond.jpg" alt="Mountains" width="600" height="400"> </a> <div class="desc">Add a description of the image here</div> </div> </div> <div class="clearfix"></div> <div style="padding:6px;"> <p>The following instance uses media queries to modify the photos on various screen sizes: on displays wider than 700px, all four will be shown side by side; on screens narrower than 700px, two images will be displayed side by side. The photos will stack vertically (100%) for displays that are less than 500px.</p> <p>Later in our CSS Tutorial, you will discover about both responsive web design and media query.</p> </div> </body> </html>