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

The alignment feature in the center is malfunctioning

I'm currently utilizing jQuery Mobile and have the following HTML along with CSS: .ui-grid-a { padding: 0; margin: 0; margin-top: 15px; height: 380px; } .ui-block-a, .ui-block-b { padding: 0; margin: 0; height: 33.3%; } .ui-block-a a, .ui-block ...

Is there a way for me to align my div with my header on the same line?

HTML: <h2> RAN shares false news story about Hershey's Oil Commitment</h2> <div class="date"> <div class="number">27</div> <div class="month">Oct</div> </div> <p>The Rainforest Action Netwo ...

Is there a way to combine multiple incoming WebRTC audio streams into one cohesive stream on a server?

I am currently working on developing an audio-conferencing application for the web that utilizes a WebSocket server to facilitate connections between users and enables streaming of audio. However, I am looking to enhance the system by transforming the serv ...

Having trouble with CSS messing up your gridview button display?

Oddly enough, whenever I place buttons inside a gridview, they end up looking very small (as shown in the image below), even though the gridview itself has no CSS applied to it. Is it possible that some other CSS is affecting the buttons? I have too much ...

What is the secret to the lightning speed at which this tag is being appended to the DOM?

Have a look at this concise sandbox that mirrors the code provided below: import React, { useState, useEffect } from "react"; import "./styles.css"; export default function App() { let [tag, setTag] = useState(null); function chan ...

What is the best way to showcase a diverse list with varying templates using Angular?

Looking to showcase a variety of items sourced from a service, each potentially belonging to different types. I am in search of a way to dynamically display distinct templates for each item based on its value or type. Is there a functionality that allows ...

Struggling with a filtering and sorting problem in my code, looking for some assistance

I'm encountering an issue with an isotope filter menu. The goal is for it to load data based on a timestamp and allow filtering. However, there seems to be a conflict between my sortBy script and the filter script. Below is the code in question: Sor ...

In React js, I wanted to display the animation specifically on the "add to bag" button for the added item

When I click the "add to bag" button, all other buttons also display the animation. How can I make sure that only the clicked button shows the animation? Any suggestions? <Table responsive> <thead> <tr> ...

JSOUP is cleverly filtering out specific tags while navigating through the HTML tree

While attempting to navigate the HTML tree of a Wikipedia page, I noticed that certain blocks of HTML elements in the code are being omitted. Is there a way to prevent these omissions? CODE Document doc = Jsoup.connect(url).timeout(10000).userAgent(USER_ ...

The changes made in the CSS file are not reflected in the browser

Recently, I encountered a strange issue with my new server where the CSS changes were not reflecting in the browser. Despite trying to refresh and clear the cache, the problem persisted. To investigate further, I used FileZilla to check if the updated CSS ...

One-of-a-kind Version: "Utilizing CSS to Capitalize an

Imagine having the following strings. i and we. me and you. he and she. Is it possible to achieve the desired result using PURE CSS? I and We. Me and You. He and She. If capitalizing the text using text-transform: capitalize is used, it will yi ...

Exploring date comparisons in TypeScript and Angular 4

I'm currently working on a comparison of dates in typescript/angular 4. In my scenario, I've stored the system date in a variable called 'today' and the database date in a variable named 'dateToBeCheckOut'. My goal was to filt ...

Tips on increasing the button size automatically as the elements inside the button grow in size

I have a button with an image and text inside, styled using CSS properties to achieve a specific look. However, I encountered an issue where the text overflows outside of the button when it's too long. I want to find a way to wrap the text inside the ...

Using a Jinja 'for' loop to create nested 'If' statements

I'm attempting to include an if statement within a loop for a jinja template: </table> <class="container"> <table border ="1"> <caption> BBOXX <caption> <thead class="thead-inverse"> <tr> <th& ...

PrimeNG - Sticky header feature malfunctioning in the p-table

Hello there, I am currently using PrimeNG p-table which features both horizontal and vertical scrolling. My goal is to implement a sticky header for the table, so far I have attempted two methods: [scrollable]="true" scrollHeight="350px" ...

Animate.css plugin allows for owl-carousel to smoothly transition sliding from the left side to the right side

I have a question regarding the usage of two plugins on my website. The first plugin is Owl Carousel 2, and the second one is Animate.css. While using `animateIn: 'slideInLeft'` with Owl Carousel 2 is working fine, I am facing an issue with `ani ...

Having trouble rendering an HTML webpage using Flask's RESTful API? Your webpage might be displaying improperly

Trying to display an HTML page on local host using a restful flask API. The content of the HTML page appears as a string with "" instead of rendering the actual page. class data(Resource): def get(self): #return "Welcome!" return rende ...

Incorrect synchronization in the SVG arrow animation

How come the arrow doesn't start moving at the same time as the line? Is there a synchronization issue? I want the arrow to begin its journey simultaneously with the line. .container{ width:100%; padding:0px; background-color: black; } .squig ...

Dealing with unreadable strings when formatting dates in a JSP

When working on a JSP project, I encountered a situation where I needed to format a Java Date retrieved from the request. My current approach looks like this: <fmt:formatDate value="${attribute.value}" pattern="yyyy-MM-dd HH:mm:ss"/> This method wo ...

Positioning an element absolutely inside a Material-UI React dialog

Currently, I am working on a Dialog component that includes a button located in the bottom right corner. When this button is clicked, it triggers the display of another div containing a list of items. However, I have encountered an issue where the list is ...