Using CSS to ensure that the cards have consistent heights when using both React and Bootstrap

I am currently working with Bootstrap 4 in React. I have encountered an issue where the card for Item 1 is shorter than that of Item 2, and I would like both cards to have the same height.

Additionally, I anticipate adding more cards at the bottom in the future.

https://i.sstatic.net/gtjPo.png

Here is a snippet from my CSS file:

.CountryDetail {
    width: 70%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin-left: 15%;
    margin-right: 15%;
}

.cards {
    background: #fcfcfc;
    margin: 20px 40px;
    transition: 0.4s all;
    width: 800px;
    padding: 20px;
    margin-left: auto;
    margin-right: auto;
}

.icon-size {
    font-size: 50px;
}

.shadow-1 {
    position: relative;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 0;
    box-sizing: border-box;
    box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.13);
}

...

And here is a portion of my JavaScript file:

<div className="CountryDetail">
    <div className="cards shadow-1 container">
        ...
    </div>

    <div className="cards shadow-1 container">
        ...
    </div>
</div>

I have attempted to adjust the line-height or height properties within the cards class; however, this ended up affecting the height of the contents inside the card.

If I try modifying the "cards" class by adding min-height like so:

.cards {
    min-height: 200px;
    ...
}

This results in the following output: https://i.sstatic.net/zlR5J.png

Answer №1

For achieving a content with the same height and centered alignment, your CSS can be updated as follows:

.containers {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 200px;
    background-color: #fcfcfc;
    margin: 20px 40px;
    transition: all 0.4s;
    width: 800px;
    padding: 20px;
    margin-left: auto;
    margin-right: auto;
}

In case you opt for display: flex for the container, and have just one direct child element (row), vertical centering can be achieved easily.

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

Using Angular: How to access a component variable within a CSS file

I'm having issues with my css file and attempting to achieve the following: .login-wrapper { background-image: url({{imagePath}}); } Below is my component code: export class LoginComponent implements OnInit { imagePath: any = 'assets/discord ...

What is the procedure to modify a CSS class from the code-behind file?

So I have a CSS style in my .css class where the color is set to blue for hundreds of buttons. But now, my customer wants an option for green buttons which will be saved by a database field. So I check the field like this: if (!String.Is ...

Switch up the background image when hovering over it

Could the proportions of the image be contributing to the issue at hand? #menu { background: black; width: 100%; height: 45px; } #menu ul { text-decoration: none; list-style-type: none; } #menu li { text-decoration: none; display: inline; font-size: ...

What is the best way to achieve a never-ending vertically scrolling image using CSS?

I want to incorporate a vertically scrolling image similar to the one on Adam Whitcroft's amazing landing page. I have tried examining his source code, but I am unable to grasp how he achieved it. The concept is to have the "I'm a scientist" text ...

Implementing a loading spinner when navigating with router.push() in next.js

When using "react-hook-form" and shadcn, I encountered an issue where I needed to display a loading spinner when the user submits a form. The new data is fetched on the page.tsx file every time the query changes, making the process time-consuming. To impro ...

Ways to Adjust the Earth's Position in WebGL Earth

I have been working with this WebGL Earth component for my project, but I am facing difficulty in adjusting the position of the planet on the canvas. My intention was to place the planet at the bottom of the page, but I haven't been able to achieve th ...

A small space underneath the <a> element nested within a <li> tag within a navigation bar

As a new programmer, I am currently working on creating a navbar. However, I have encountered an issue where there are small gaps underneath the user when my cursor hovers over it. There is a white gap under the user element. I expect that the hover back ...

Ensure Focus Retention Upon Clicking Inside Iframe with li a:focus

How can I prevent my ul.SideNav_Main li a:focus class from losing focus when I click on the iframe or elsewhere on the page? Shouldn't it maintain focus until I click on another URL in the list? Is it possible to solve this issue with just CSS, or wo ...

Modify how various classes are shown when hovering over a pseudo class

This is my customized scss code .image-container { position: relative; .delete-image { display: none; position: absolute; top: 0px; right: 0px; } .make-primary { display: none; position: absolute; ...

Issue with component not updating upon state change

Having trouble getting my react function component to rerender immediately after updating the state. The application takes input for material cost of each product and calculates the total. I want the component to display the updated total as soon as the i ...

Importing ReactDOM alone does not result in the rendering of anything

Having just started delving into the world of React, I've been grappling with getting a React app up and running. Despite my efforts, all I can manage to see is a blank page. Can anyone offer some assistance? HTML Markup (index.html) <html> & ...

What causes the fixed div to appear when scrolling horizontally?

I have replicated this issue in a live example: http://jsfiddle.net/pda2yc6s When scrolling vertically, a specific div element sticks to the top. However, if the window is narrower than the wrapper's width and you scroll horizontally, the sticky elem ...

Can a create-react-app be created on a virtual private server (VPS)?

I am eager to begin working on a create-react-app project on a VPS so my client can monitor my progress. While I understand you can "Add React to a Website," I am unsure how to incorporate libraries into my site using the tutorial provided on the ReactJS ...

Using Visual Studio Code, I am eager to upload a new version to GitHub via React

I've successfully created a Github repository and managed to push updates in the past, but I still lack confidence in my abilities. Could someone provide guidance on how to commit a new update to GitHub using Vscode's terminal? ...

Having trouble with the preview feature when resizing images

Before trying to implement the JSFiddle was working correctly: http://jsfiddle.net/qa9m7t33/ However, after attempting to implement it, I encountered some issues: http://jsfiddle.net/z1k538sm/ While trying to resize an image, I realized that this example ...

How can I retrieve the current background color and revert it back after a .hover event?

I am trying to use the .hover function to change the background color of a menu. Each menu item has a different background color, so I want it to return to its original color when the user hovers off. In other words, I want the script to read the current b ...

Are none of the page links clickable?

Currently, I am in the process of creating a portfolio website. This is my first attempt at coding HTML and CSS from scratch without the aid of a layout template. I've encountered an issue that has me stumped - the links within the container are not ...

Encountering a problem while trying to install the Firebase module on Node.js: getting a

I am interested in integrating Firebase into my React application. As a newcomer to React, I followed this tutorial to create my app: https://reactjs.org/tutorial/tutorial.html My environment details: Node.js version: v8.9.4 npm version: 5.6.0 Upon ...

I'm looking to retrieve the selected value from my autocomplete box in React using the Material UI library. How can I

Here is a snippet of code that utilizes an external library called material ui to create a search box with autocomplete functionality. When a value is selected, an input tag is generated with the value "selected value". How can I retrieve this value in ord ...

Move the modal dialog so it appears closer to the top of the page

I am facing a challenge with my jQuery modal dialog. While it is loading properly, I am restricted to using an older version of jQuery (1.12.4) and cannot upgrade it. My goal is to center the modal close to the top of the page, similar to how it is positio ...