bulma Scale image to container
Asked Answered
A

3

7

I followed the documentation example and have this inside a media object:

<figure class="image is-128x128">
  <img src="https://bulma.io/images/placeholders/128x128.png">
</figure>

I use that as part of a card for a display of multiple elements.

The problem is that when an image is uploaded which is not squared (meaning the ratio is not 1:1), the image overflows the container effectively breaking the layout.

Is there any way to fix this in bulma?

Allspice answered 31/1, 2019 at 19:33 Comment(2)
could you solve this issue ?Keeshakeeshond
No, I had to write the CSS to force the image to that size.Allspice
B
2

Basic CSS can solve this, use object-fit: cover; on the image.

Belomancy answered 20/10, 2022 at 18:59 Comment(0)
O
1

I centered the image inside the 128x128 area like this:

<figure class="is-flex is-align-items-center is-justify-content-center image is-128x128">
  <img src="https://bulma.io/images/placeholders/480x640.png">
</figure>

<figure class="is-flex is-align-items-center is-justify-content-center image is-128x128">
  <img src="https://bulma.io/images/placeholders/640x480.png">
</figure>

Then I added this css override:

.image img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}
Orfield answered 15/9, 2021 at 11:25 Comment(0)
D
-1

If you give the <figure> tag the class "is-square", probably this might fix your issue.

It scales the container to the size of the image but on the other hand the image doesn't look good because of the ratio.

<figure class="image is-128x128 is-square">
  <img src="https://bulma.io/images/placeholders/128x128.png">
</figure>
Djambi answered 5/6, 2020 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.