Bootstrap 4: Organize 5 cards in a row with each line populated with cards

My Bootstrap setup looks like this:

<div class="container">
  <div class="row">
    <div class="col-12 col-lg-3">              
      <div class="card mb-3 cardtrans">
// All the content for the card goes here. 
      </div>
    </div>
  </div>
</div>

I have a PHP loop to display multiple cards.

Currently, I have 4 cards aligned in a row using the code above. How can I adjust it so that there are 5 cards per row without adding extra CSS? Do I need to apply different classes?

Answer №1

Customizing Bootstrap 4.6.x

To achieve a responsive layout, you can utilize the row-cols-lg-5 class from Row Columns. This eliminates the need to set individual column widths, allowing you to simply specify the number of columns in the row and let Bootstrap handle the rest by automatically wrapping the overflow to the next row.

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" rel="stylesheet" />

<div class="container">
  <div class="row row-cols-lg-5">
    <div class="col-12">
      <div class="card mb-3 cardtrans">Card 1</div>
    </div>
    <div class="col-12">
      <div class="card mb-3 cardtrans">Card 2</div>
    </div>
    <div class="col-12">
      <div class="card mb-3 cardtrans">Card 3</div>
    </div>
    <div class="col-12">
      <div class="card mb-3 cardtrans">Card 4</div>
    </div>
    <div class="col-12">
      <div class="card mb-3 cardtrans">Card 5</div>
    </div>
    <div class="col-12">
      <div class="card mb-3 cardtrans">Card 6</div>
    </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

Smooth animation is not being achieved with the Jquery dlmenu

I have implemented a multi-level navigation menu using a demo of the jquery dlmenu plugin v1.0.2. Although most of the functions are working smoothly, the CSS3 menu navigation lacks the fluidity of the jQuery left/right sliding effect. Is there a way to ...

Arranging the rows and columns of a table in optimal alignment

I am currently facing an issue with two tables. The first table consists of 2 rows and 4 columns, with the first column spanning 2 rows. However, in the visual representation, the last 3 columns are misaligned with the rows. How can this alignment be corre ...

The HTML/CSS authentication system is experiencing technical difficulties and is not functioning as intended

I came across this code on codepen.io and tried to implement it using the provided HTML and CSS. However, I encountered some errors during implementation. While the code works perfectly in the CodePen compiler, it doesn't seem to be error-free. One i ...

Is it allowed to modify <li> tag only when it contains a <strong> child element?

Is it possible to use SCSS to change the background color of a li element based on whether its child is a strong tag or not? li { margin-left: 3px; margin-bottom: 3px; border: solid transparent; background-color: #fff; border-top-left-radius: ...

The Next.js Image component does not implement the maxWidth attribute

<Image src="/assets/blog/image.webp" style={{ maxWidth: "700px" }} width={1400} height={1400} /> Issue Detected The image with src '/assets/blog/image.webp' has the following styles applied, but they are being overwrit ...

Inquiry regarding the grid structure within my react application

When attempting to arrange my images in a grid layout, I encountered a strange issue after applying CSS grid. The grids ended up being organized horizontally instead of how I wanted them to be - two or three images per line. The component hierarchy is as ...

Unable to show inline within web forms application utilizing bootstrap

I am currently modifying the account registration section of a new VS 2013 web application that uses bootstrap css for formatting. I am working on creating a form on a page and struggling to get one section to display inline instead of as a block element. ...

Changing Location of Carousel in Bootstrap

Recently, I have been working with Bootstrap and have encountered a problem with the carousel. I have placed carousel images below my navbar, but there seems to be a gap between the navbar and the carousel image. I want the image to be right below the navb ...

What is the best way to apply styling to an image that is contained within the document.write function?

I'm looking to customize the design of this cat image, but I'm struggling to locate where to incorporate the div class. It's likely a basic step, but as a beginner in JavaScript, I'm hoping that someone can assist me. document.write(&ap ...

Tips on how to align bullet points in a list

I'm currently working on a little exercise that requires me to replicate this However, I'm facing some difficulty aligning the bullets as shown in the reference. My content is aligned but not the bullets. Here's the link This is my HTML: ...

Drag a dropdown menu to the bottom left corner and set it to full width on mobile using CSS

Check out this code snippet with CSS and HTML: CSS .flyout { position: absolute; top: 30px; right: 15px; background-color: #FFF; padding: 20px; border: 1px solid #eaeaea; z-index: 999; width: 400px; border-top: 3px solid #337AB7; disp ...

Column spilling over with cards

Having a card with a form in it, I wanted to implement a y-scroll bar to control the visibility of the form on the page. However, it seems that the columns are extending beyond the boundaries of the card. .card { box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2 ...

I recently attempted a meyers reset and now I'm struggling to get my unordered list to display in a horizontal layout

Check out my code snippet below: .navbar-container { width:100%; display:inline-block; } ul { list-style-type: none; display: inline; } <div class="navbar-container"> <ul> <li><a href="gmail.com">Gmail</a>& ...

Align a component vertically in a FlexBox using Material UI

I have a React app where I created a card with specified min width and height, containing only a header. I want to add flexbox that occupies the entire left space with justify-content="center" and align-items="center". This way, when I insert a circular pr ...

Struggling with a minor glitch in a straightforward coin toss program written in JavaScript

I'm a newcomer to JavaScript programming and I am struggling with understanding how the execution flow is managed. I attempted to integrate an animation from "Animation.css" into a coin toss program, but encountered an issue. When trying to use JavaSc ...

The alignment of my Navbar Brand is off in my Navigation Bar and won't align to

<body> <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <div class="container-fluid"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs ...

How to keep a div element fixed on the page's border vertically and horizontally adhered

Would you mind visiting the following link: and observing the layout of the page? My goal is to affix or "attach" a small div element to the right side of the page, just slightly outside of the right frame of the page. Vertically, I want this div to be ...

Spin only the outline with CSS

I have a unique idea for my webpage - three spinning circles surrounding text, while the text itself remains stationary. My challenge is to achieve this effect using only CSS, specifically by utilizing the .spinner-border class from Bootstrap. I cannot ma ...

Guide to aligning a URL in an HTML file

Greetings all, I'm new to HTML and struggling with how to center a URL on my webpage. For example: <a href="http://www.google.com"> Click Here to Open Google </a> I attempted using the tag and the STYLE attribute but without success. ...

MVC encounters difficulty generating content and script files following view addition

Encountering an issue with creating an MVC empty project and adding a View from the controller. The _Layout.cshtml file is generated, but content, script, and font files are not being created. Any suggestions for resolving this? https://i.sstatic.net/45Di ...