Utilizing Bootstrap's inline-block feature for card layouts

My current challenge involves using Bootstrap 4 cards within a modal. Regardless of the number of cards I implement, they all end up in a single row. Ideally, I would like to have a maximum of 3 cards per row. Another issue arises when resizing the window, as the cards become too compact and unreadable.

I attempted to solve this problem by utilizing:

display: inline-block;

However, this approach did not yield the desired outcome.

<div class="portfolio-modal mfp-hide" id="labrador-modal">
    <div class="portfolio-modal-dialog bg-white">
      <a class="close-button d-none d-md-block portfolio-modal-dismiss" href="#">
        <i class="fa fa-3x fa-times"></i>
      </a>
      <div class="container text-center">
        <div class="card-group">
          /* Card content here */
        </div>
     </div>
</div>

The image below demonstrates how the layout looks with 3 cards:

While this arrangement appears satisfactory, adding an extra card results in overcrowding. The same issue occurs when resizing the page, as shown in the following screenshot:

Answer №1

To make your cards fit as the window narrows, you can utilize flexbox and apply a wrap feature. Simply add the following CSS properties to the card-group div:

display: flex;
flex-wrap: wrap;

Alternatively, you can use Bootstrap flex and wrap classes on the card-group div like this:

<div class="card-group d-flex flex-wrap">

Make sure to set a default width value for all the cards, such as width: 300px.

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

Can you please elaborate on how the CSS properties: -webkit-border-radius and border-radius are utilized?

https://i.sstatic.net/ILDTb.png What is the reason for having different values of 25px for -webkit-border-radius and border-radius in various positions? table.cal{ color: #064525c; border-spacing: 0; border: 3px solid black; -webkit-bor ...

Stacking of div tags on top of each other

Looking for assistance with some CSS challenges. I am attempting to design a group of buttons using div tags, but they are all merging into one another. You can find the code at http://codepen.io/CliffTam/pen/gadEaq Could someone review the code and pro ...

Can markers be positioned on top of scroll bars?

Looking for a way to display small markers on the scrollbar of an overflow: scroll element, similar to features found in IDEs and text editors like this one: https://github.com/surdu/scroll-marker. I've considered using a pointer-events: none overlay ...

Issues arising with transferring information between components

My webpage had a header with a search engine input, a list of posts, and pagination all on one page. I made the decision to separate the header into its own component in a different Vue file. However, after making this change, searching for posts by their ...

A guide on obtaining meta tag content values and calculating their average

Currently, I am in the process of developing a website that makes use of Schema.org microdata to provide structured content for product listings. One thing I have come across is that Google requires an aggregate rating based on all the reviews. How can I e ...

Is there an advantage to pre-rendering a circle on an HTML5 canvas for improved performance?

Is it more efficient to pre-render graphics for a basic shape like a circle on an off-screen canvas? Would there be noticeable improvements in rendering performance when dealing with 100 circles at game-like framerates? What about 50 circles or just 25? ...

Bidirectional binding of attributes in an Angular directive

I have developed a custom Angular Directive known as evoEventMirror. Its main purpose is to attach a jQuery event to an inserted element and apply a specified CSS style to the "root" element. Refer to the example below: <div id="#mydiv" evo-event-mirro ...

Loading Ajax content into div (Wordpress) without pre-loading the font can cause display issues

Currently, I'm implementing a JavaScript function within Wordpress using Ajax to load the content of a post into a modal div when specific elements are clicked. Here is an example of how the JS function appears: function openProjectModal($that) { ...

How can I automatically center a Vimeo iframe vertically without having to manually adjust the position?

I'm trying to adjust a popular fluid jQuery script so that it can automatically center a vimeo video vertically, without any black bars. A little horizontal cropping is acceptable. Here is my current code: HTML <div class="container"> < ...

Is it possible to conceal a link once it has been visited?

I am trying to figure out how to remove a link from a page once it has been visited. However, I am facing privacy restrictions with the :visited pseudo-class. Is there a way to achieve this without using display: none? For example: .someclass a:link {dis ...

`Incompatibility with background-position on y-axis in Mozilla Firefox`

I am having trouble with this code. It appears to work well in Chrome, but not in Mozilla Firefox. Could it be that this property is not supported in Firefox? Is there an alternative solution? .background { background:url('icon.png') no-repeat ...

Ways to update the image in a hover container

I am working on a project with HTML code and I am trying to create a hover effect for an image. I want the image to change when hovering anywhere on the box, not just on the image itself. I have tried adding multiple classes and ids, but the image only cha ...

Stacking the FontAwesome icons on a PrimeNG button

I've been experimenting with various methods to incorporate stacked icons on a pButton in Primeng, but I haven't had any success. Does anyone have a solution that doesn't result in the button being twice its normal height? Here are a couple ...

What caused Safari to only show half of the page?

Whenever I browse my website using Safari, I noticed that if the total size of the content on the first page is less than 100vh, Safari ends up cutting off half of the page. To fix this issue, I added a CSS rule in the body setting min-height to 110vh wh ...

Adjust size of item within grid component in VueJS

I have a grid container with cells and a draggable item in a Vue project. I am trying to figure out how to resize the box inside the grid component (refer to images). https://i.stack.imgur.com/q4MKZ.png This is my current grid setup, and I would like the ...

Text alignment below a div with absolute positioning

Presently, my setup looks something like this: <div class="mycol" id="mycanvas" style="z-index: -1; top:150px;left:240px;width:88%; height:80%; position: absolute;background-color:red;"> </div> <div class="testclass"> He ...

I am looking to optimize my custom tailwindcss file by reducing its size

Here is the structure of my package.json file. "scripts": { "start": "yarn run watch-css && craco start", "build": "yarn run build-css && craco build", "test": "craco test ...

Seeking assistance with CSS - need to adjust block layout based on media query - considering using flexbox

I struggle with HTML5/CSS and have a simple task of laying out three DIVs differently based on screen size, using @media declarations. Layout 1 Layout 2 +----- container -----------------+ +----- container -------------- ...

What is the best way to retrieve the height of the parent element in my specific situation

I am facing an issue in my directive where I need to access the height of the parent element. Here is a snippet of my code: (function(window, angular) { var app = angular.module('myApp'); app.directive('testElem', [ fu ...

What is the reason behind the change in size and shape of the text when using "overflow: hidden"?

Check out this interactive demo using the provided HTML and CSS: You can view the demo by clicking on this link. /*CSS*/ .header { margin: 0px; padding: 0px; width: 100%; } .headertable { padding: 0px; margin: 0px; width: 100%; border-sp ...