Answer the question
In order to leave comments, you need to log in
Positioning an image inside a block?
I use bootstrap and flex blocks to create a grid of goods for an online store. It is necessary to properly process images so that they fit into a block with a certain height. And all the images are very different, from the phone to the refrigerator).
So far I have only such a code (for the image)
<div class="img-block">
<img href="something.img" />
</div>
Answer the question
In order to leave comments, you need to log in
I would venture to suggest, perhaps not the best, but a quick and almost hassle-free option using background-image
<div class="img-block" style="background-image: url(something.img)">
<img href="something.img" />
</div>
<div class="img-block" style="background-image: url(something.img)">
</div>
.img-block {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.img-block img {
opacity: 0;
}
<img>
you can completely delete it. img {
width: 100%;
height: 100%;
object-fit: cover; // contain
}
If the Aspect Ratio is different (aspect ratio 1:1, 3:2, 8:5 etc) then I think the robots will not help you in this case, when the product cards must be the same size - only handmade, customized by hand, or by hiring a designer and content manager
if for an online store, then it’s better not to use flex, but use css grid
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question