Remove white space in filterable gallery

I have created a gallery block for a filterable gallery for logos. There are 8 categories and when the user clicks on a button it shows a set of logos pertaining that industry. Art and Technology, Beauty, Fashion etc..

The issue is that when the page loads, even though only the filtered logos are shown, the space for all logos is still being accounted for in the layout, leading to excessive negative space. To address this, you need to ensure that the container adjusts its height dynamically based on the visible content. Here’s how you can achieve this: Ensure only visible logos affect the container height. Hide non-visible logos properly so they don’t take up space.

the css i have added is this:

`/* General Styles */
.gallery-section {
  position: relative;
  z-index: 1;
}

.title {
  font-size: 46px;
  font-weight: 700;
  font-family: "Playfair Display", serif;`
  color: #f44336;
}

.filter {
  text-align: center;
  max-width: 1050px;
  margin: auto;
}

.abc {
  display: none !important;
}

.btn {
  padding: 10px 12px;
  margin: 5px 8px;
  display: inline-block;
  color: #003;
  background: #FFF;
  border: white;
  transition: all 0.4s;
  font-size: 13px;
  font-weight: 300;
  text-decoration: none;
  position: relative;
}

.btn::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 4px;
  bottom: 0;
  left: 0;
  background-color: #e0fef4;
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

.btn:hover::after,
.btn-active::after {
  transform: scaleX(1);
}

/* Gallery Styles */
.gallery {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  margin: 50px auto;
  max-width: 1200px;
  overflow: hidden; /* Hide overflow to prevent extra space */
}

.gallery a {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 40px;
}

.gallery img {
  max-width: 250px;
  max-height: 200px;
  object-fit: contain;
  transition: transform 0.3s ease-in-out;
  border-radius: 12px;
}

.gallery img:hover {
  transform: scale(1.05);
}

.sets .hide,
.sets .pophide {
  display: none; /* Hide non-visible logos */
}

/* Modal Styles */
.closeBtn {
  position: absolute;
  font-size: 22px;
  font-weight: 500;
  right: 25px;
  top: 25px;
  color: white;
  transition: 0.5s linear;
  padding: 8px 40px;
  border-radius: 25px;
  background: red;
  outline-offset: -6px;
  outline: 2px solid #fff;
}

.closeBtn:hover {
  cursor: pointer;
  background: white;
  color: black;
  outline: 2px solid #000;
}

.openDiv {
  width: 100%;
  height: 100vh;
  background: #000000e7;
  position: fixed;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  left: 0;
  z-index: 9999;
}

.imgPreview {
  width: 70%;
  object-fit: scale-down;
  max-height: 40vw;
  height: auto;
}

.prevButton,
.nextButton {
  transition: 1s linear;
  padding: 10px 35px;
  font-size: 18px;
  border: none;
  color: white;
  background: #0005;
  border-radius: 10px;
  border: 1px solid white;
  margin: 10px;
}

.prevButton:hover,
.nextButton:hover {
  background: #fff;
  color: black;
}

the code injection code i have added is this:
 

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
  document.addEventListener("DOMContentLoaded", function() {
    // Function to filter logos
    function filterLogos(filter) {
      let logos = document.querySelectorAll('.sets a');
      logos.forEach(function(logo) {
        if (logo.classList.contains(filter)) {
          logo.style.display = 'block';
        } else {
          logo.style.display = 'none';
        }
      });
    }

    // Initially show Art logos
    filterLogos('Art');

    // Add event listeners to filter buttons
    let filterButtons = document.querySelectorAll('.filter a');
    filterButtons.forEach(function(button) {
      button.addEventListener('click', function(e) {
        e.preventDefault();
        let filter = button.getAttribute('href').substring(1);
        filterLogos(filter);
        // Add active class to the clicked button
        filterButtons.forEach(function(btn) {
          btn.classList.remove('btn-active');
        });
        button.classList.add('btn-active');
      });
    });

    // Image preview functionality
    let imgs = document.querySelectorAll('.sets a img');
    let count;
    imgs.forEach((img, index) => {
      img.addEventListener('click', function(e) {
        if (e.target == this) {
          count = index;
          let openDiv = document.createElement('div');
          let imgPreview = document.createElement('img');
          let butonsSection = document.createElement('div');
          butonsSection.classList.add('butonsSection');
          let closeBtn = document.createElement('button');
          let nextBtn = document.createElement('button');
          let prevButton = document.createElement('button');
          prevButton.innerText = 'Previous';
          nextBtn.innerText = 'Next';

          nextBtn.classList.add('nextButton');
          prevButton.classList.add('prevButton');
          nextBtn.addEventListener('click', function() {
            if (count >= imgs.length - 1) {
              count = 0;
            } else {
              count++;
            }
            imgPreview.src = imgs[count].src;
          });

          prevButton.addEventListener('click', function() {
            if (count === 0) {
              count = imgs.length - 1;
            } else {
              count--;
            }
            imgPreview.src = imgs[count].src;
          });

          closeBtn.classList.add('closeBtn');
          closeBtn.innerText = 'Close';
          closeBtn.addEventListener('click', function() {
            openDiv.remove();
          });

          imgPreview.classList.add('imgPreview');
          imgPreview.src = this.src;

          butonsSection.append(prevButton, nextBtn);
          openDiv.append(imgPreview, butonsSection, closeBtn);

          openDiv.classList.add('openDiv');
          document.querySelector('body').append(openDiv);
        }
      });
    });
  });
</script>

please help!```


[screenshot](https://i.sstatic.net/UDLN6foE.png)

New contributor

Shreya Kothari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật