The alignment of Bootstrap 4 cards is not coming together as expected

Good morning,

I'm currently working on organizing my Bootstrap card elements into rows of 3 cards each. I want the cards to be uniform in height and width, with spacing between them. For instance, if I have 7 cards, I'd have 3 rows of three cards and the last row would have a single card, yet it should be the same size as the cards above it.

Here is my code:

<div class="container pt-2">
  <div *ngFor="let g of carMultiArray">
    <div class="row">
      <div class="col-12">
        <div class="card border-0 boxShadow no-padding col-lg-4 col-md-12 col-sm-12 col-xs-12" *ngFor="let t of g">
          <a data-toggle="modal" href="'#'+ 'car'+t.Id" class="card-link" [attr.data-target]="'#'+ 'car'+t.Id" style="color:black; text-decoration: none;">
            <img class="card-img-top rounded-0" src="{{t.MainImage}}">
          </a>
          <div class="card-body text-center">
            <div class="my-arrow">
              <img *ngIf="!t.Verified" src="../../icons/error.png">
              <img *ngIf="t.Verified" src="../../icons/checked.png">
            </div>
            <h5 class="card-title">{{t.Title}} {{t.Kubatura}} {{t.BodyType}}</h5>
            <h6 class="card-subtitle mb-2 text-muted">{{t.FuelType}} {{t.GearBox}} {{t.Horsepower}}
              {{t.OdometerReading}}</h6>
            <a [routerLink]="['/car', t.Id]" class="card-link">More</a>
            <a class="card-link">{{t.City}}</a>
            <a class="card-link">{{t.FirstRegistration}} </a>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

My CSS (though not directly related to the issue):

.boxShadow {
    display: inline-block;
    vertical-align: middle;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
  }

  .card-body {
    position: relative;
  }

  .my-arrow {
    position: absolute;
    top: -10%;
    right: 10%;
  }

  .card-img-top {
    width: 100%;
    height: 17vw;
    object-fit: cover;
  }

  .card{
    width: 90%;
  }

  .no-padding {
    padding-left: 0;
    padding-right: 0;
  }

The issue I'm facing is that, with the current code, the cards have no margin or padding between them when in the same row. I have removed all padding in the .no-padding class. Adding any margin pushes the 3rd card to a new line. Putting the elements in a card-group doesn't create space between them, and adding space breaks the grid. Organizing them in a card-deck results in the last card in a row taking up the whole space.

How can I achieve the desired result I'm looking for?

I hope this explanation is clear, but if not, please feel free to ask.

Answer №1

Consider implementing the .justify-content-between class provided by bootstrap4 and removing the display: inline-block property from the .boxShadow element for improved design.

Answer №2

IF YOU WANT TO USE BOOTSTRAP, CHECK OUT THIS LINK.. W3 bootstrap 4 card deck

IF YOU PREFER TO AVOID BOOTSTRAP, HERE IS THE CODE FOR YOU..

.parent{
text-align:center;
}
.padding_maker{
display:inline-block;
padding:10px;
}
.children{
display:inline-block;
background-color:black;
height:300px;
width:150px;
color:white;
}
<div class="parent">
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>

</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

Disable the 'bouncy scrolling' feature for mobile devices

Is there a way to prevent the bouncy scrolling behavior on mobile devices? For example, when there is no content below to scroll, but you can still scroll up and then it bounces back when released. Here is my HTML structure: <html> <body> ...

Incorporating a Bootstrap Modal (Pop-up window) into the Navbar of a

How can I successfully integrate a Bootstrap Modal into my Django Navbar? Despite following the official Bootstrap documentation, I am encountering issues in my Django project. Is there a way to make this work? <!-- Button trigger modal --> <bu ...

Iterating through two classes in a Javascript loop

Hello, I'm facing a small obstacle that I'm hoping to overcome using JavaScript/jquery. Essentially, I have multiple div classes and I want to create a loop that adds a class to specific divs without manually assigning an id to each one. The goal ...

Javascript problem: Trouble with event.clientX position

I found a great resource on learning javascript at this website, I'm having trouble understanding the code snippets in function XY(e, v), specifically these two lines: event.clientX + document.documentElement.scrollLeft and event.clientY + document ...

Showing a collection of cards within a dynamic container set up in a 3x3 grid layout to start

In an attempt to showcase cards within a responsive container utilizing bootstrap and django, my goal is to create a 3x3 grid layout on extra-large screens with scrollable overflow that adjusts based on device width. Initially, I experimented with wrapping ...

Creating a CSV file using an AJAX request in PHP

In my current project involving PHP AJAX DATATABLE within the Drupal framework, I have successfully developed a function to create a CSV file from table records. This function is triggered by clicking a button in HTML or accessing a specific URL. The PHP ...

Navigating to User's Specific Info Page using Node.js

Would love some input on my current issue. I have a table featuring a list of users, and my goal is to display user information in detail whenever a user (which corresponds to a row in the table) is clicked. The process involves identifying which user was ...

My keyframes seem to be malfunctioning, despite exhausting all my troubleshooting options

Could someone please help me figure out why the @keyframes rule is not working for me? I've tried adding -webkit- as a fix, but it doesn't seem to be helping at all. .keyframe { height: 15px; width: 50px; background-color: red; -webkit ...

What is the best way to utilize variables in order to style this image inside a selector?

Struggling with adding dynamic styling to an image inserted into a div through a selector. Despite successful testing of the style changes, I am stuck on how to assign variable values for the properties. Various syntax attempts have failed so far. functi ...

What is the best way to perform calculations within a PHP loop for <input> elements and then display the results using a JavaScript loop?

Hello everyone, I'm currently struggling with displaying the calculations from a loop of input tags. What I'm trying to achieve is having 5 rows with input fields. At the end of each row, there should be a span area that displays the calculation ...

Counter is effective for the initial post, yet it does not function properly for the subsequent post

Can anyone help with an issue I'm having with my JavaScript counter? It works for the first comment, but not the second one. This problem persists whether I use PHP or JavaScript. Below is the JavaScript code for the counter: var count = (function() ...

Extract JSON data from Python API

Currently, I am delving into web programming and have created a Python API that queries an SQL database to return a JSON. The functionality of the API is as expected. In parallel, I've developed a controller where I execute a GET request to utilize t ...

Chrome browser CSS trapezoid shape clickability problem

I am attempting to make a trapezoidal perspective shape clickable for the entire area. It's currently working in Firefox and IE, but I'm encountering issues with Chrome. Here is a demonstration of the shape and a link: http://jsfiddle.net/9n9uh6 ...

Function activation in Element requires a double click to initiate

I've encountered an issue with a web element I'm working on where the click function only triggers after the first click, rendering the initial click ineffective. Here's the code snippet in question: HTML: <div> <a href="#0" cla ...

Identify when a mouse hovers within 10 pixels of a div using jQuery

Is it possible to detect when a user hovers over a specific area within a div using JavaScript or jQuery, without adding any additional tags? -------------------------------- -------------------------------- -------------------------------- -------- ...

Utilize the div element to segment a webpage into four different sections

Within a div tag, I have used 4 other div tags to create equal areas. Is there an alternative method to achieve this division or improve it? <div style="width: 689px; margin-left: 215px; margin-top: 0px; float: none; height: 502px;"> ...

Utilize Material icons in CSS for a list in Angular 9

My task involves altering the HTML provided by a content management system for one of our applications. Specifically, I need to replace all "ul"s with <mat-icon>check_circle_outline</mat-icon> instead of the default "." The challenge lies in t ...

What is the best way to assign a dynamic width to a block element?

In my project, I am working with 30 elements that have the class .lollipop and are styled with line-height: 30px; height: 30px;. <a class="lollipop">Random text</a> <a class="lollipop">Random text longer</a> <a class="lollipop"& ...

How can we determine the total character count of a file that has been loaded into a textarea

I have a textarea where I can count the number of characters as I type. function calculateCharacters(obj){ document.getElementById('numberCount').innerHTML = obj.value.length; } <textarea name="textField" id="my_textarea" class="text_edit ...

Is it possible to execute a server-side click on a div element?

I have a div with an image and name inside. How can I make this div trigger a server-side click event without changing its structure? Here is my code: <div class="tutorial" style="margin-left:5px;"> TUTORIAL<div class="firstico" style=" ...