Bento Gallery Layout Using HTML And CSS

Hey there, You are most welcome to this article. I hope you will enjoy this article. If you like this article then please share this article with your friends and colleagues. If you have any questions or suggestions regarding this article then please comment down below.

📙Table Of Content

Project Folder Structure of Bento Gallery Layout:

  • Create a file called index.html to serve as the main file.

  • Create a file called style.css for the CSS code.

Bento Gallery Layout HTML CODE

  
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bento Gallery Layout</title>
    <link rel="stylesheet" href="./styles.css">
  </head>
  <body>
    <div class="gallery">
      <div class="card">
        <img src="./imgs/01.jpg">
      </div>
      <div class="card">
        <img src="./imgs/02.jpg">
      </div>
      <div class="card">
        <img src="./imgs/03.jpg">
      </div>
      <div class="card">
        <img src="./imgs/04.jpg">
      </div>
      <div class="card">
        <img src="./imgs/05.jpg">
      </div>
      <div class="card">
        <img src="./imgs/06.jpg">
      </div>
    </div>
  </body>
</html>
  
  

Bento Gallery Layout CSS CODE


*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  height: 100vh;
  background-color: #051115;
  display: flex;
  justify-content: center;
  align-items: center;
}

img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.gallery {
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, 180px);
  gap: 10px;
  margin-inline: 30px;
}

.gallery > .card {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgb(77, 77, 77);
}

.card:nth-child(1) {
  grid-area: 1 / 1 / 2 / 2;
}

.card:nth-child(2) {
  grid-area: 2 / 1 / span 1 / span 1;
}

.card:nth-child(3) {
  grid-area: 1 / 2 / span 2 / span 2;
}

.card:nth-child(4) {
  grid-area: 1 / 4 / span 1 / span 1;
}

.card:nth-child(5) {
  grid-area: 1 / 5 / span 1 / span 1;
}

.card:nth-child(6) {
  grid-area: 2 / 4 / span 1 / span 2;
}

@media screen and (max-width: 800px) {
  .gallery {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 220px);
  }

  .card:nth-child(1) {
    grid-area: 1 / 1 / span 1 / span 1;
  }

  .card:nth-child(2) {
    grid-area: 2 / 1 / span 1 / span 1;
  }

  .card:nth-child(3) {
    display: none;
  }

  .card:nth-child(4) {
    grid-area: 1 / 2 / span 1 / span 1;
  }

  .card:nth-child(5) {
    grid-area: 1 / 3 / span 1 / span 1;
  }

  .card:nth-child(6) {
    grid-area: 2 / 2 / span 1 / span 2;
  }
}

@media screen and (max-width: 500px) {
  .gallery {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 150px);
  }

  .card:nth-child(1) {
    grid-area: 1 / 1 / span 1 / span 1;
  }

  .card:nth-child(2) {
    grid-area: 2 / 1 / span 1 / span 1;
  }

  .card:nth-child(3) {
    display: none;
  }

  .card:nth-child(4) {
    grid-area: 1 / 2 / span 1 / span 1;
  }

  .card:nth-child(5) {
    display: none;
  }

  .card:nth-child(6) {
    grid-area: 2 / 2 / span 1 / span 1;
  }
}


Live Preview of Bento Gallery Layout Using HTML And CSS

How to run this Html Css and Js Project in Our Browser?

first, you need a code editor either you can use VS code studio or notepad and then copy the html,css, and javascript code, create separate or different files for coding then combine them, after creating file just click .html file or run from VS Code studio and you can project preview.

Which Code Editor do you use to create those projects?

I am using VS Code Studio.

is this project responsive or not?

Yes! this project is a responsive project.

If you enjoyed reading this post and have found it useful for you, then please give share it with your friends, and follow me to get updates on my upcoming posts. You can connect with me on  Instagram

if you have any confusion Comment below. I can help!

Bye-bye