bootstrap 4 grid of responsive cards

I am attempting to replicate the layout of CodePen's dashboard or, if you do not have an account, you can view CodePen's home screen.

My goal is to create a dynamic list of cards that are responsive and adjust the number of cards displayed in a row based on the viewport size.

I thought using Bootstrap would help achieve this functionality, but my attempts have been unsuccessful so far. It is important to note that the number of cards may vary dynamically.

Here is the progress I have made so far in this CodePen:

<div class="row">
    <div class="col-md-2 " style="margin-bottom:10px;">
        <div class="card card-default" >

            <button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>
            <h3>Card</h3>
            <h6>Today</h6>
            <p><strong>5 Errors</strong></p>
            <p><strong>3 Warnings</strong></p>
            <p><strong>1 Info</strong></p>
        </div>
    </div>

    ...
    
</div>

The current display looks like this: https://i.sstatic.net/v89Qr.png

However, when I decrease the window width, the layout becomes distorted. I want the cards to flow into the next row while utilizing the full available width space. https://i.sstatic.net/EAd8N.png

My objective is to achieve a layout similar to this: https://i.sstatic.net/JUmyg.png

Scaling down... https://i.sstatic.net/Rb1A8.png

Further scaling down... https://i.sstatic.net/RTeOv.png

Answer №1

Utilize Bootstrap's responsive breakpoints to design your layout effectively. Here is an example:

<div class="col-lg-3 col-md-4 col-sm-6" style="margin-bottom:15px;">
      <div class="card card-default">
          ...
      </div>
</div>

Check out the live demo here

Answer №2

Utilize various 'col' classes to accommodate different window sizes.

class="col-xs-6 col-sm-4 col-md-3 col-lg-2"

In this instance, the layout of the cards will be as follows: 6 on large screens, 4 on medium screens, 3 on small screens, and 2 on very small screens.

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

How can I use jQuery to set up form validation for an input textfield?

Check out this code snippet: <form data-test="loginForm-container" novalidate="" method="POST" enctype="multipart/form-data"> <div class="css-o5d3v1 e1ovefus2"> <div data-test="guestForm-email-wrapper" class="e1ovefus1 css-yjv4po e1eu3s ...

Troublesome tab key function in FireFox causing navigation issues

I'm facing an issue with the tab key focus on links in FireFox. Strangely, it's working fine in Chrome but in FireFox, it keeps looping within one element. For better understanding, I have created a demo showcasing this behavior specifically in ...

The tooltip malfunctions when I incorporate the PHP variable

When I use PHP variables to return an HTML span tag, I am encountering an issue. The span tag contains a title field where I bind my PHP data. However, it seems to only accept the first sentence of my PHP value, causing it to not work properly. Below is th ...

Mouseover feature for image is functioning, but having issues with alignment

I am currently working on displaying images upon mouse over actions. While the functionality is working perfectly, I am facing an issue where the displayed images appear below and the last image takes up space at the bottom. To rectify this problem, I woul ...

What is the best way to incorporate a style attribute into my EJS page content?

Having trouble with adding custom style. It seems to work, but there's an error displayed. Apologies for my poor english :( <div class="card card_applicant"> <div class="card_title" style="background-c ...

Stretching a row in Wordpress Visual Composer and setting the direction to Right-to-Left

Whenever I attempt to expand a row using the row settings in Visual Composer, the row stretches but the alignment of the row becomes completely off. This issue only occurs when the body direction is set to direction:rtl in the CSS. You can view the websit ...

numerous sections within a solitary webpage

I need to implement multiple tabs on a single page, how do I modify the code to make this possible? Take a look at the codepen for reference. Here is the jquery code I have written so far: var tabs = $(".tabContainer ul li a"); $(".tabConten ...

The output is visible in the Firefox console but does not display on the actual browser

Can anyone help me with a bug in my javascript/jQuery/PHP/mySQL application? When I submit a form, the response is visible in the Firebug console window but not in the browser window. I know this is a vague question, but I'm hoping it might be a commo ...

How to dynamically add table rows and cells with JavaScript using a single selection input

I am working on a project that involves a selection input with around 5 options. Additionally, there is an empty table that follows this format: <table> <tr> <td>X (for deletion)</td> <td>Option name</td> ...

Center the two consecutive <div> elements within the container

There is a situation where <div id="container"> <div id="div2">Title</div> <div id="div3">text text</div> </div> and in this scenario, #container { height:500px; width:100%; text- ...

Looping through two arrays of objects using Angular's NgFor directive

I need to iterate through two separate arrays using ngFor in order to display their content in an html format. <div class="form-check ml-5" *ngFor="let item of competencias.competencias; let i = index"> <input class=" ...

Change the color of a specific day on the Arshaw Calendar using CSS

Can anyone help me with changing the color of the box in the month view in the arshaw calendar? I've been attempting to do so using this script, but my lack of expertise in javascript is proving to be a hurdle. The goal is for this script to be called ...

How can Selenium and Python be used to refresh a webpage until a specific item is found?

I'm attempting to continuously refresh the page until a specific item appears, but my current code is not working. I took inspiration from this solution: python selenium keep refreshing until item found (Chromedriver). Below is my code snippet: whil ...

What is the method for inserting a new <p> tag whenever a user sends a new message in ReactJS?

Whenever I press the Enter key, the content is updated in the same tag. First I sent Hello World! The second time I tried to send Hello as a new message, it was updated within the same tag. I have shared code snippets related to the messaging function ...

Mixing strings with missing slashes in links

console.log(mylink) When using the console to log mylink, the expected result is a normal link like http://example.com/something.jpg. I tried concatenating it as shown below: var html = '<div id="head" style="background:linear-gradient(rgba(0, 0 ...

PHP code that removes a table row from a database

Can anyone help me troubleshoot my code? My PHP seems to be functioning, but for some reason the delete button is not working! if(isset($_POST['delete'])) { $ID = $_POST['value']; $delete = "DELETE FROM tbl_document WHERE ID = ...

How to Adjust CSS Animation Background to Fully Cover Responsive Height

Hi there! I've been working on adding some CSS code to my ReadyMag project, but I'm having trouble with odd aspect ratio browser windows. The code I have is almost doing what I want, but it's not covering the full width and height. How can I ...

using javascript to change a link's state with a click action

I have a question that is related to the topic discussed here: Making a link stay active displaying hover effect upon click using javascript. I am looking for a way to disable the active class when the same link is clicked again. Any assistance on this mat ...

Scss - Only one for mobile devices

Just dipping my toes into scss and I've got a quick question. Here's the snippet of scss code I'm working with: .page { max-width: 1200px; position: relative; width: 100%; ul{ background-color: black; width ...

How can I animate scrolling up or down using jQuery and CSS?

I have a a element that triggers an action when clicked: <a href="#" class="hel" onclick="YPCP1_();">Scroll down</a> Also, function YPCP_(){ var scroll = $(window).scrollTop(); window.scrollTo(0, 600); } The function successfully sc ...