PORTFOLIO GRID

by davidxmartins

HTML

<main>
  <div class="gallery">
    <a href="https://google.com" class="gallery-item">
      <img src="https://via.placeholder.com/400x300" alt="Image 1">
      <div class="overlay">+</div>
    </a>
    <a href="page2.html" class="gallery-item">
      <img src="https://via.placeholder.com/400x300" alt="Image 2">
      <div class="overlay">+</div>
    </a>
    <a href="page3.html" class="gallery-item">
      <img src="https://via.placeholder.com/400x300" alt="Image 3">
      <div class="overlay">+</div>
    </a>
    <a href="page1.html" class="gallery-item">
      <img src="https://via.placeholder.com/400x300" alt="Image 1">
      <div class="overlay">+</div>
    </a>
    <a href="page2.html" class="gallery-item">
      <img src="https://via.placeholder.com/400x300" alt="Image 2">
      <div class="overlay">+</div>
    </a>
    <a href="page3.html" class="gallery-item">
      <img src="https://via.placeholder.com/400x300" alt="Image 3">
      <div class="overlay">+</div>
    </a>
    <a href="page3.html" class="gallery-item">
      <img src="https://via.placeholder.com/400x300" alt="Image 3">
      <div class="overlay">+</div>
    </a>
  </div>
</main>

CSS

.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px;
}

.gallery-item {
  position: relative;
  width: calc((100% - 2 * 10px) / 3);
  /* Adjusted calculation */
  overflow: hidden;
  border-radius: 5px;
  background-color: #000;
}

.gallery-item::before {
  content: "";
  display: block;
  padding-top: 75%;
  /* 4:3 Aspect Ratio */
}

.gallery-item img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease-in-out;
}

.gallery-item .overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  opacity: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  font-size: 3rem;
  transition: opacity 0.3s ease-in-out;
}

.gallery-item:hover img {
  transform: scale(1.1);
}

.gallery-item:hover .overlay {
  opacity: 1;
}

/* Responsive: 2 items per row */
@media (max-width: 1000px) {
  .gallery-item {
    width: calc(50% - 10px);
  }
}

/* Responsive: 1 item per row */
@media (max-width: 700px) {
  .gallery-item {
    width: 100%;
  }
}