MultiWEBPress
Wordpress & Shopify Experts

MultiWEBPress
Wordpress & Shopify Experts

How to create responsive image gallery using html and css?

Hello Friends, Today in this blog you’ll learn how to create a How to create responsive image gallery using html and css?. This is for beginners who want to learn new stuff using HTML & CSS. Recently, I have shared a How to create pagination using html css? | Now it’s time to create Responsive image gallery using   HTML & CSS.

Video tutorial of Responsive Image Gallery using HTML and CSS

You may also like:

In the video, you’ve seen the css image gallery. There are many different ways to create this image grid html css one of which is the way we have designed it.

Responsive image gallery using html and css?s[Source Codes]

So to create this, Image Gallery you have to create three different files. The 3 files are index.html , style.css & script.js. Remember when you create an HTML file don’t forget to add a .html extension on HTML file and .css extension to your style file. 

JAVASCRIPT CODE

Let’s create a Js file with the name of script.js and paste the below codes. Remember you’ve to create a file with a .js extension

				
					    $(".gallery").magnificPopup({
      delegate: 'a',
      type: 'image',
      gallery:{
        enabled: true
      }
    });

				
			

Let’s create a Cascading Style Sheet(CSS) file with the name of style.css and paste the below codes in your CSS file. Remember you’ve to create a file with a .css extension

CSS CODE

				
					@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@600&display=swap');

*{
  margin: 0;
  padding: 0;
  font-family: 'Poppins', sans-serif;
  box-sizing: border-box;
  background: #4f4d4d;
}

.gallery-section{
  width: 100%;
  padding: 50px 0;
}

.inner-width{
  width: 100%;
  max-width: 1300px;
  margin: auto;
  padding: 20px 20px;
}

.gallery-section h1{
  font-size: 4vw;
  padding-bottom: 20px;
  text-align: center;
  text-transform: uppercase;
  color: #fff;
}

.gallery-section .gallery a {
  padding: 10px;
}

.border{
  width: 180px;
  height: 4px;
  background: #333;
  margin: 60px auto;
}

.gallery-section .gallery{
  display: flex;
  flex-wrap: wrap-reverse;
  justify-content: center;
}

.gallery-section .image{
  flex: 25%;
  overflow: hidden;
  cursor: pointer;
}

.gallery-section .image img{
  width: 100%;
  height: 100%;
  transition: 0.4s;
  border-radius: 25px;
}

.gallery-section .image:hover img{
  transform: scale(1.6);
}

@media screen and (max-width:960px) {
  .gallery-section .image{
    flex: 33.33%;
  }
}

@media screen and (max-width:768px) {
  .gallery-section .image{
    flex: 50%;
  }

  .gallery-section h1{
    font-size: 22px;
  }
}

@media screen and (max-width:480px) {
  .gallery-section .image{
    flex: 100%;
  }
}

				
			

Now create a Hypertext Markup Language(HTML) with the name of index.html and paste the below codes in your HTML file. Remember you’ve to create a file with a .html extension

HTML CODE

				
					<!DOCTYPE html>
<!-- Created By MultiWebPress - www.multiwebpress.com -->
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="style.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>
<body>

    <div class="gallery-section">
      <div class="inner-width">
        <h1>Responsive Image Gallery</h1>
        <div class="gallery">

          <a href="img/1.jpg" class="image">
            <img decoding="async" src="img/1.jpg" alt="">
          </a>

          <a href="img/2.jpg" class="image">
            <img decoding="async" src="img/2.jpg" alt="">
          </a>

          <a href="img/3.jpg" class="image">
            <img decoding="async" src="img/3.jpg" alt="">
          </a>

          <a href="img/4.jpg" class="image">
            <img decoding="async" src="img/4.jpg" alt="">
          </a>

          <a href="img/5.jpg" class="image">
            <img decoding="async" src="img/5.jpg" alt="">
          </a>

          <a href="img/6.jpg" class="image">
            <img decoding="async" src="img/6.jpg" alt="">
          </a>

          <a href="img/7.jpg" class="image">
            <img decoding="async" src="img/7.jpg" alt="">
          </a>

          <a href="img/8.jpg" class="image">
            <img decoding="async" src="img/8.jpg" alt="">
          </a>

        </div>
      </div>
    </div>
    <script src="script.js"></script>
  </body>
</html>

				
			

After creating these two files & pasting codes, now run the files in your browser. You can run to any browser you have on your computer. (Google Chrome, Firefox, Internet explorer etc.)

That’s all, now you’ve successfully created responsive image gallery html css. If your code does have any bugs/errors/ or you’re facing any problems, then please comment down below or contact us from the contact us page.

Hope you enjoyed reading and watching the video. Please do like and subscribe to my youtube channel & follow me on Instagram.

Thanks in Advance!

SHARE

WhatsApp
Facebook
Twitter
LinkedIn
Telegram

Leave a Comment

Your email address will not be published. Required fields are marked *

*
*