How to Ensure Cards Stay The Same Height/Width

Issue

I have this code, where I have 3 CSS cards in a row with bootstrap.

        <div class="container mt-4">
            <div class="row">
                <div class="col-auto mb-3">
                    <div class="card" style="width: 18rem;">
                        <div class="card-body">
                            <div class="reward12"><h1 class="rewardtext12">#50</h1></div>
                            <h5 class="card-title">Hiya how is your day been this is extra long text ?</h5>
                            <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                           <center><button type="button" class="btn btn-info" disabled="disabled">Status - Claimed</button></center>
                            Tag: <span class="tag tag-teal">CSS/HTML</span>
                            <div class="user">
                                <img src="https://yt3.ggpht.com/a/AGF-l7-0J1G0Ue0mcZMw-99kMeVuBmRxiPjyvIYONg=s900-c-k-c0xffffffff-no-rj-mo" alt="user" />
                                <div class="user-info">
                                  <h5>Joey Jenkins</h5>
                                  <small><strong>30s ago</strong></small>
                                </div>
                              </div>
                        
                        </div>
                    </div>
                </div>
                <div class="col-auto mb-3">
                    <div class="card" style="width: 18rem;">
                        <div class="card-body">
                            <div class="reward12"><h1 class="rewardtext12">#50</h1></div>

                            <h5 class="card-title">Card title</h5>
                            <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                            <center><button type="button" class="btn btn-danger" disabled="disabled">Status - Completed</button></center>
                            Tag: <span class="tag tag-teal">CSS/HTML</span>
                            <div class="user">
                                <img src="https://yt3.ggpht.com/a/AGF-l7-0J1G0Ue0mcZMw-99kMeVuBmRxiPjyvIYONg=s900-c-k-c0xffffffff-no-rj-mo" alt="user" />
                                <div class="user-info">
                                  <h5>Joey Jenkins</h5>
                                  <small><strong>30s ago</strong></small>
                                </div>
                              </div>

                        </div>
                    </div>
                </div>
                <div class="col-auto mb-3">
                    <div class="card" style="width: 18rem;">
                        <div class="card-body">
                            <div class="reward12"><h1 class="rewardtext12">#50</h1></div>

                            <h5 class="card-title">Card title</h5>
                            <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                            <center><button type="button" class="btn btn-success">Claim</button></center>
                            Tag: <span class="tag tag-teal">CSS/HTML</span>
                            <div class="user">
                                <img src="https://yt3.ggpht.com/a/AGF-l7-0J1G0Ue0mcZMw-99kMeVuBmRxiPjyvIYONg=s900-c-k-c0xffffffff-no-rj-mo" alt="user" />
                                <div class="user-info">
                                  <h5>Joey Jenkins</h5>
                                  <small><strong>30s ago</strong></small>
                                </div>
                              </div>


                        </div>
                    </div>
                </div>
                        </div>
            <h3>Hi</h3>
<br>
        </div>

<style>
    .user {
  display: flex;
  margin-top: auto;
}

.user img {
  border-radius: 50%;
  width: 40px;
  height: 40px;
  margin-right: 10px;
}
.user-info h5 {
  margin: 0;
}
.user-info small {
  color: #545d7a;
}

    .reward12 {
        background: green;
        font-weight: bold;
text-align: center;
font-size: large;
height: 30px;
  border-radius: 30px;
  font-size: 12px;
  margin: 0;
  color: #fff;
  padding: 2px 10px;
  text-transform: uppercase;
  cursor: context-menu;

    }
    .rewardtext12 {
        font-size: 20px;
        font-family: 'PT Sans', serif;
        font-weight: bold;

    }
    .tag {
  background: #cccccc;
  border-radius: 50px;
  font-size: 12px;
  margin: 0;
  color: #fff;
  padding: 2px 10px;
  text-transform: uppercase;
  cursor: pointer;
}
.tag-teal {
  background-color: #47bcd4;
}
.tag-purple {
  background-color: #5e76bf;
}
.tag-pink {
  background-color: #cd5b9f;
}
</style>

This is the result
enter image description here

As you can see, the first card’s height is more because of the longer text length. Is there a way to ensure that the card’s height will remain the same even with different size text? (Like turn some of the text into … if there is too much?)

Solution

You just need to give the height and width of 100%

width:100%;
height:100%;

Or if you are using flex then

you can give

flex-grow:1; 
height:100%;

Answered By – Henil Mehta

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published