#The height of the Image component should be fixed, and the width should be auto. How to achieve?

1 messages · Page 1 of 1 (latest)

gusty yachtBOT
#

Hi @old goblet. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

You can achieve this by using the style prop in the Image component. The style prop allows you to apply CSS directly to the Image component. You can set the height to a fixed value and width to auto. Here's how you can do it:

<Image
    src={avatar}
    alt="official avatar"
    priority
    style={{
        height: '48px',
        width: 'auto',
    }}
/>

Please note that the style prop is not a replacement for width, height, or layout props. The width and height props are still required for determining the aspect ratio of the image.

Also, keep in mind that setting both width and height to auto in the style prop doesn't make sense as it would make the image lose its aspect ratio. It's usually one or the other.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@old goblet kapa.ai is still learning and improving, please let us know how it did by reacting below

old goblet
#

Yes, however in that case I can't set the "sizes" attribute at all which can be a problem. Or not?