Excessive content on Bootstrap card causing overflow beyond designated background height

I am facing a challenge with my HTML/CSS (Bootstrap 5.0) code. My goal is to create a Pinterest-style Masonry card gallery using Bootstrap 5.0 grid system along with the Masonry library available at Masonry. However, I encounter an issue where the content overflows beyond the background container's height and the cards start stacking on top of each other until window resize occurs.

Is there a more effective way to implement a Masonry layout within Bootstrap 5.0 or can you spot any flaws in my code that could be causing this overflow/stacking problem? Please let me know if additional information or code is needed:

<!DOCTYPE html>
        <html lang="en">
            <head>
                <meta charset="utf-8" />
                    ...
            </head>
            <body>
                ...
            </body>
        </html>
    

Non-Bootstrap CSS Properties


        :root {
            --light: #7C766A;
            --dark: #4D473E;
            ... 
        }

        .background-image{
            background-image: url('...');
              position: absolute;
              ...
          }
          
          a:link { color:var(--blue);  }
          ...

          @media (min-width: 576px) {
              .h-sm-100 {
                  height: 100%;
              }
          }

          @media (max-width: 600px) {
            ...
          }

          @media (min-width: 600px) {
            ...
          }
    

Edit:

Here is an image illustrating the overflow/stacking issue:

Answer №1

For the masonry layout focus (aside from a few other height issues), the problem lies with the <img> element in each card. Consider replacing <img> with a <div> and using a background-image instead. While this may impact image aspect ratios, you can use padding-top as a clever workaround. Here's an illustration:

<div style='
background-image: url("https://picsum.photos/id/237/200/300");
background-color: #cccccc; 
background-repeat: no-repeat; 
background-size: cover; 
width: 100%; 
height: 0; 
padding-top: 150%'></div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The hamburger menu is not functioning properly online, but it works perfectly in xampp/localhost

I'm currently facing a challenge with my responsive menu. It works perfectly on my offline server in mobile format, but as soon as I upload it to the real server, it stops working. I've been grappling with this problem for hours. Here's the ...

Issue with iOS Mobile Safari Navigation Bar/Toolbar when changing orientation

Experiencing some unexpected behavior with iOS mobile safari on version 13.3. I have a website that functions as a single page application for the most part. Due to this, I have set its height/width at 100% and adjusted the content accordingly. While ever ...

Retrieve a specific key from SQL records

I have recently started learning JavaScript and MySQL. When I run a MySQL query in my server-side JavaScript code, the returned rows are in the following format: For example, if I use console.log(rows), it will display: [ RowDataPacket { id: 7080, ...

Having difficulty loading themes in AngularJS Material

I have added Angular (1) Material (v.1.1.5) to my Visual Studio project using NuGet and followed their instructions for referencing it: <script src="scripts/angular.min.js"></script> <script src="scripts/angular-route.min.js"></script ...

What is the reason behind the requirement of two elements in an event listener?

Here is a snippet of code with two event listeners: window.addEventListener("click", jump); window.addEventListener("click", jump()); The issue lies in the fact that removing either of these listeners renders them invalid and non-funct ...

Managing the triggering of the automatic transition in view models

My question is straightforward and requires no elaborate explanation. Can Durandal be configured to control the use of transitions when transitioning between viewmodels? The motivation behind wanting to disable the animation is as follows: I have a sear ...

How can I write a JavaScript function that eliminates all white spaces within a string?

Exploring ways to create a custom function that trims white spaces from the beginning and end of a string (including \n, \t) without relying on built-in methods like trim(), replace(), split(), or join() Here’s an example code snippet showcasi ...

How to Activate Animation Post-Page Load in Angular 8, Overcoming ExpressionChangedAfterItHasBeenCheckedError

Trying to solve a crucial question concerning animating an element after the page has fully loaded. Despite extensive research, I have yet to find a simple and efficient solution. Can anyone offer some advice? Once the mobile page is loaded, I want the log ...

The toggle feature in jQuery doesn't hide content in the same manner as it was originally shown

Just diving into the world of jquery and I'm experimenting with the toggle function to display and hide a div, along with adding or removing an active class. http://jsfiddle.net/MAkyw/ I've encountered 2 issues: 1) The 'active' class ...

What could be causing the appearance of white lines in my rendered 3D obj file when using three.js?

I'm perplexed by the appearance of white lines in my rendered 3D model using three.js. Could these be part of the wireframe? It seems that some meshes weren't separated properly, leading to this issue. I'm unsure about how to remove the wire ...

Utilize JavaScript or jQuery to align a list item center on a horizontal scrolling navigation bar

Currently, I am utilizing bootstrap 4.6 for a webpage, and while the default navbar doesn't meet my requirements for mobile navigation, I am attempting to customize it to function like MODE_SCROLLABLE in Android. Therefore, I need it to activate the l ...

Observing the state object in Pinia does not trigger when the object undergoes changes

I am facing an issue with setting a watcher on a deeply nested object in my Pinia state. export const useProductStore = defineStore("product", { state: () => ({ attributes: {}, }), }); When the object has data inside it, it looks something like ...

What is the best method for storing information in the database?

I recently built a Customer model in Django but I'm encountering an issue with saving the data to the database table. Whenever I click the signup button, it redirects me back to the home page instead of completing the registration process. Here are sn ...

Error: The function authClient.request is not recognized in Node.js with googleapis

I am currently utilizing googleapis and google auth for managing events on Google Calendar. While I was able to successfully fetch the calendar event list, encountering an error when attempting to insert a new event. The error message being thrown is: Type ...

Navigate to specific location within a hidden overflow

<ul id="the-list" style="overflow:hidden;height:100px;> <li><a id="link1" href="#">Link 1</a></li> <li><a id="link2" href="#">Link 2</a></li> <li><a id="link3" href="#">Link 3< ...

Using JavaScript to store a JSON string as the value of an input field (Escaping/Unescaping)

Here is the scenario to consider (view plunker here: http://plnkr.co/edit/fOJ5zRvqCKvOC3olik8S?p=preview): https://i.sstatic.net/8fz6s.png <input ng-model="x" type="text"> <button ng-click="add(x)"> push input's value </button> Th ...

The element in TS 7023 is implicitly assigned an 'any' type due to the fact that an expression of type 'any' is not valid for indexing in type '{}'

I have implemented a select-box that includes options, labels, optgroups, and values. Is my approach correct or is there something wrong with the way I have defined my types? interface Option { label: string value: string selected?:boolean mainGrou ...

Achieving a child div to occupy the entire available space when the parent is specified as `mx-auto` can be accomplished using Vue and Tailwind CSS

Sorry if this seems like a basic question, I'm still getting the hang of Vue and tailwind. In my parent template, it looks like this: <template> <div class="mx-auto mt-4 max-w-3xl"> <slot></slot> </div> ...

Tips on waiting for Vue component's asynchronous mount to complete before proceeding with testing

In my Vue2 component, I have an asynchronous lifecycle hook method: // create report when component is loading async mounted(): Promise<void> { await this.createReport(); } Now, I want to test my component using jest and vue/test-utils, but the te ...

Hovering over rounded corners is being blocked by transparent areas

I have a setup that resembles the following: http://jsfiddle.net/NhAuJ/ The issue arises when hovering near the edges of the circle because the square div blocks interaction with the background. I want to ensure that the circular div in the middle remain ...