Is there a way to maintain the responsive layout of Bootstrap 4 while applying object-fit: cover;
to an image in a card element? This would help ensure that the image fits properly without sacrificing responsiveness.
#imgUNcover {
width: 285px;
height: 145px;
-o-object-fit: cover;
object-fit: cover;
-o-object-position: center;
object-position: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="col-12 col-md-6 col-lg-3 mb-3 mb-md-3">
<div class="card">
<div class="img-container">
<a href="index.php?post=<?php echo $UN['title']?>"><img src="<?php echo $UN['capa']?>" alt="<?php echo $UN['alt']?>" class="card-img-top" id="imgUNcover"></a>
</div>
<div class="card-body">
<a href="index.php?post=<?php echo $UN['title']?>" class="card-title cardTitleLink">
<h1 class="cardTitleUN">
<?php echo $UN['title']?>
</h1>
</a>
<p class="card-text text-muted">
<?php echo $UN['text']?>
</p>
<a href="index.php?post=<?php echo $UN['title']?>" class="btn btn-outline-danger btn-sm">Continue Lendo</a>
</div>
</div>
</div>
If we don't apply object-fit: cover;
:
https://i.sstatic.net/HTIbp.png
But with object-fit: cover;
:
https://i.sstatic.net/ZtanO.png
Although changing the width
of the image using the id #imgUNcover
may not fully address the issue on different screen resolutions.
Edit: