Responsive image gallery using grid-layout - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:Image

Description

Responsive image gallery using grid-layout

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">

.gallery {<!--from w  w w  .  j a  v a2  s  .c  o  m-->
   display: grid;
   grid-gap: 5px;
}
.gallery img {
   width: 100%;
   height: 100%;
}
@media (max-width: 575.98px) {
   .gallery {
      grid-template-columns: repeat(1, 1fr);
   }
}
@media (max-width: 768.98px) and (min-width: 576px) {
   .gallery {
      grid-template-columns: repeat(2, 1fr);
   }
}
@media (max-width: 991.98px) and (min-width: 768px) {
   .gallery {
      grid-template-columns: repeat(3, 1fr);
   }
}
@media (max-width: 1199.98px) and (min-width: 992px) {
   .gallery {
      grid-template-columns: repeat(4, 1fr);
   }
}
@media (min-width: 1200px) {
   .gallery {
      grid-template-columns: repeat(5, 1fr);
   }
}


      </style> 
 </head> 
 <body> 
  <div class="gallery"> 
   <a> <img src="https://www.java2s.com/style/demo/InternetExplorer.png"> </a> 
   <a> <img src="https://www.java2s.com/style/demo/Opera.png"> </a> 
   <a> <img src="https://www.java2s.com/style/demo/Safari.png"> </a> 
   <a> <img src="https://www.java2s.com/style/demo/Opera.png"> </a> 
   <a> <img src="https://www.java2s.com/style/demo/InternetExplorer.png"> </a> 
   <a> <img src="https://www.java2s.com/style/demo/Safari.png"> </a> 
   <a> <img src="https://www.java2s.com/style/demo/Opera.png"> </a> 
   <a> <img src="https://www.java2s.com/style/demo/Firefox.png"> </a> 
   <a> <img src="https://www.java2s.com/style/demo/Opera.png"> </a> 
  </div>  
 </body>
</html>

Related Tutorials