Adjusting the content of mat-cards to fill in blank spaces

I have encountered an issue with the alignment in a list using mat-card.

Here is my current layout: https://i.stack.imgur.com/VKSw4.jpg

Here is the desired layout: https://i.stack.imgur.com/8jsiX.jpg

The problem arises when the size of content inside a mat card increases. The next mat card should adjust its space automatically without leaving a blank space corresponding to the previously larger mat card.

Below is the relevant CSS and HTML code:

.works {
    padding-left: 47px;
    padding-top: 99px;
    
    // display: inline-flex;
  }
  .work-head {
    // width: 330px;
    // height: 28px;
  
    font-family: Raleway-SemiBold;
    font-style: normal;
    font-weight: 500;
    font-size: 24px;
    line-height: 28px;
    // text-align: center;
  
    color: #000000;
  }
  
  ...

</div>

Answer №1

See the solution for your problem in the example below.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">


<div class="row">
  <div class="col-6">
    <div class="row">
      <div class="col-12">
        <div class="card border p-3 mb-2">
          <p>Lorericies nisl eget tincidunt. Vestibulum id pulvinar risus. Nam viverra pretium luctus. Morbi turpis tortor pretium luctus. Morbi turpis torto pretium luctus. Morbi turpis torto</p>
        </div>
      </div>
      <div class="col-12">
        <div class="card border p-3 mb-2">
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor ultricies nisl eget tincidunt. Vestibulutor</p>
        </div>
      </div>
      <div class="col-12">
        <div class="card border p-3 mb-2">
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor ultricies nisl eget tincidunt. Vr risus. Nam viverra pretium luctus. Morbi turpis tortor</p>
        </div>
      </div>
      <div class="col-12"> 
        <div class="card border p-3 mb-2">
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor ultricies nisl eget tincidunt. Vestibulum id pulvinar risus. Nam viverra pretium luctus. Morbi turpis tortor</p>
        </div>
      </div>
    </div>
    </div>
    <div class="col-6">
      <div class="row">
        <div class="col-12">
        <div class="card border p-3 mb-2">
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempoar risus. Nam viverra pretium luctus. Morbi turpis tortor</p>
        </div>
      </div>
      <div class="col-12">
        <div class="card border p-3 mb-2">
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor ultricies nisl eget tincidunt. Vestibulum id pulvinar risus. Nam viverra pretium luctus. Morbi turpis tortor</p>
        </div>
      </div>
      <div class="col-12">
        <div class="card border p-3 mb-2">
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor</p>
        </div>
      </div>
      </div>
    </div>
  </div>


<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js&" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous&"</script>

Answer №2

If you're struggling with a common CSS issue, consider implementing a masonry layout. Utilize the column-count rule in your CSS along with inline-block elements to achieve this effect. It's important to include a media query to ensure that the layout adjusts responsively.

For more information, check out this informative article or take a look at this helpful example.

By following these steps, you can create a masonry layout without relying on external CSS or JS libraries.

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

URL for image preview on Amazon S3

Is there a way to retrieve preview images from my Amazon S3 image storage instead of always fetching the full-sized 5MB images? If necessary, I would then be able to request the normal image. ...

Expanding the size of a div using the Bootstrap grid system

I need to customize the width of the date column on my inbox page so that it displays inline without breaking the word. Even when I use white-space: nowrap, the overflow hides it due to the fixed width. I want the name and date classes to be displayed in ...

The amazingly efficient Chrome quick find feature, accessible by pressing the powerful combination of Ctrl + F, ingeniously

Currently using Google Chrome version 29.0.1547.62 m. I've employed the CSS attribute overflow set to hidden on the parent element, which renders some of my DIV elements hidden from view. Additionally, these concealed DIV elements are adjusted in pos ...

What sets justify-content apart from align-items?

I'm really struggling to grasp the distinction between these two properties. After conducting some research, it appears that justify-content can handle... space-between and space-around, while align-items is capable of... stretch, baseline, initial, a ...

Encountering a "undefined response" issue within an Angular

I am encountering an issue when trying to fetch data from a REST API. Upon logging the response, I am getting an undefined value. How can I resolve this? I have confirmed that the API is sending data by checking my network tab in the developer tool. getPro ...

Issue with content not wrapping inside the body tag (apart from using float or setting body and html to 100

Why on earth is the body/html or .main div not wrapping my .container div's when the browser width is between 767-960 px?! This is causing horizontal scrolling and I am completely baffled. This should definitely be working! The only code I have is: ...

CSS styles are combined and included at the beginning of the index.html file

During the creation of a production version of my Angular 9.0.4 application, I noticed that the CSS is bundled and placed at the top of the dist/index.html file as shown below: <link rel="stylesheet" href="styles.6ea28d52542acb20a4c6.css"><!docty ...

React.js Material UI Dropdown Component

Is it possible to modify the behavior of the dropdown in Material UI Select? I would like to customize the appearance of <ul> so that it does not resemble a pop-up. My goal is for the selected item to be contained within the <li> element, simi ...

Regulation specifying a cap of 100.00 on decimal numbers entered into a text input field (Regex)

I have created a directive that restricts text input to only decimal numbers in the text field. Below is the code for the directive: import { HostListener, Directive, ElementRef } from '@angular/core'; @Directive({ exportAs: 'decimal ...

What is the best way to resize an HTML element to fill the remaining height?

I'm struggling with adjusting the height of a node-webkit app to fit the current window size. See below for an image depicting what I am aiming for. Intended Goal : HTML Markup : <body> <div class="header"> THIS IS A HEADER W ...

The center alignment doesn't seem to function properly on mobile or tablet devices

I've designed a basic webpage layout, but I'm facing an issue with responsiveness on mobile and tablet devices. The problem seems to be related to the width: 100% property in my CSS, but I can't seem to pinpoint the exact solution. While tr ...

Is there a way to make a <div> load automatically when the page starts loading?

I'm having an issue with my code where both <div> elements run together when I refresh the page. I want them to display separately when each radio button is clicked. <input type="radio" name="cardType" id="one" class="css-checkbox" value="db ...

I cannot locate the dropdown list anywhere

As a beginner in html and css, I decided to follow a tutorial on youtube. The tutorial focuses on creating a navigation bar with dropdown menus using html and css. I wanted the names Ria, Kezia, and Gelia to be displayed when hovering my mouse over the Su ...

Issue with Bootstrap 5: Mobile Menu Failure to Expand

I’ve been struggling with this issue for days now. I’ve searched everywhere for a solution, but to no avail. That’s why I’m turning to the experts here for help :-) The problem I’m facing is that my mobile menu won’t open. Nothing happens when ...

``I am experiencing issues with the Ajax Loader Gif not functioning properly in both IE

I am brand new to using ajax and attempting to display a loading gif while my page loads. Interestingly, it works perfectly in Firefox, but I cannot get it to show up in Chrome or IE. I have a feeling that I am missing something simple. The code I am using ...

The act of updating Angular 2 to Angular 4 has resulted in an issue where the 'AnimationDriver' member is not being exported

After upgrading my Angular 2 to Angular 4, I encountered an error message when running my project: The module 'node_modules/@angular/platform-browser/platform-browser' does not have the exported member 'AnimationDriver'. ...

Is it possible to save the location of a draggable box using CSS3?

I'm trying to figure out how to store the position of a box in a fluid sortable row. Essentially, I want the position to be remembered when a user drags a box from category 1 to category 2, even after refreshing the page. Below is the HTML code for t ...

Activate animation while scrolling the page

I am using a progress bar with Bootstrap and HTML. Below is the code snippet: $(".progress-bar").each(function () { var progressBar = $(this); progressBar.animate({ width: progressBar.data('width') + '%' }, 1500); }); <body> & ...

Retrieve all colors from the style attribute

I'm on the hunt for a method to extract all CSS colors from a website. Currently, I have been able to manage internal and external stylesheets by utilizing document.styleSheets. However, my issue lies in the fact that any styles directly assigned to a ...

Output information to the specified divID using Response.Write

Currently, I have knowledge of javascript and I am currently expanding my skills in ASP.NET C#. My goal is to achieve the following task using javascript: document.getElementById('divID-1').innerHTML= '<p>Wrong Password< ...