У меня есть этот код, где у меня есть 3 карты CSS подряд с начальной загрузкой.
<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>
Это результат
Как видите, высота первой карточки больше из-за большей длины текста. Есть ли способ гарантировать, что высота карты останется неизменной даже с текстом разного размера? (Например, превратить часть текста в ..., если его слишком много?)
Вам просто нужно указать высоту и ширину 100%
width:100%;
height:100%;
Или, если вы используете flex, то
Вы можете дать
flex-grow:1;
height:100%;