Home > Net >  How to make product cards equal height Bootstrap5
How to make product cards equal height Bootstrap5

Time:04-29

How to make product cards equal height? Unfortunately, flex is not working.

.product-card {
  position: relative;
  padding: 1px;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-direction: column;
  flex-direction: column;
  background: #fff;
}

image

CodePudding user response:

Just add h-100 class on the div where you have added the border class. Check example below.

<div >
      <div >
        <div >
          <div >
            <img
              src="https://static.wixstatic.com/media/2c0034_400708cb5f7d44bcb1f272ebc2a51aab~mv2.png"
              alt=""
              
              width="100"
            />
            <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Pariatur, quod?</p>
            <p>$850.00</p>
          </div>
        </div>
        <div >
          <div >
            <img
              src="https://static.wixstatic.com/media/2c0034_400708cb5f7d44bcb1f272ebc2a51aab~mv2.png"
              alt=""
              
              width="100"
            />
            <p>
              Lorem ipsum dolor sit amet consectetur, adipisicing elit. Pariatur, quod?Lorem ipsum dolor sit amet consectetur,
              adipisicing elit. Pariatur, quod?
            </p>
            <p>$850.00</p>
          </div>
        </div>
        <div >
          <div >
            <img
              src="https://static.wixstatic.com/media/2c0034_400708cb5f7d44bcb1f272ebc2a51aab~mv2.png"
              alt=""
              
              width="100"
            />
            <p>
              Lorem ipsum dolor sit amet consectetur, adipisicing elit. Pariatur, quod?Lorem ipsum dolor sit amet consectetur,
              adipisicing elit. Pariatur, quod?Lorem ipsum dolor sit amet consectetur, adipisicing elit. Pariatur, quod?
            </p>
            <p>$850.00</p>
          </div>
        </div>
      </div>
    </div>

CodePudding user response:

You can try something like this. I've created a container for all the cards and each card will have a flex layout with a direction of column. In order for cards being the same height we need to fill the space between the image and the price (description) by using flex-grow: 1. See the implementation for more details.

.product-card-container {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 1px solid green;
  justify-content: space-evenly;
}

.product-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 200px;
  padding: 0 0.4rem;
  row-gap: 0.5rem;
  border: 1px solid black;
}

.product-card > img {
  object-fit: cover;
  width: 100%;
  height: 200px;
}

.product-info {
  /* Use this for growing an element to 100% width or height inside of a flex container */
  flex-grow: 1
}
<div >

  <div >
    <img src="https://live.staticflickr.com/5217/5471047557_4dc13f5376_n.jpg">
    <span >Short description</span>
    <span><b>$850.00</b></span>
  </div>
  
  <div >
    <img src="https://live.staticflickr.com/5217/5471047557_4dc13f5376_n.jpg">
    <span >Long long long long long long long long long description</span>
    <span><b>$850.00</b></span>
  </div>
  
  <div >
    <img src="https://live.staticflickr.com/5217/5471047557_4dc13f5376_n.jpg">
    <span >Very long long long long long long long long long long long long long long long long long long long long long description</span>
    <span><b>$850.00</b></span>
  </div>
  
  <div >
    <img src="https://live.staticflickr.com/5217/5471047557_4dc13f5376_n.jpg">
    <span >Short description</span>
    <span><b>$850.00</b></span>
  </div>
  
</div>

  • Related