I have a problem with my image : the height attribute is not working. Here is my code :
<img
alt="..."
className="img-fluid floating"
src={Landing1}
style={{ height: '300px', width: 'auto' }}
/>
And when I try this code :
<img
alt="..."
className="img-fluid floating"
src={Landing1}
style={{ width: '300px', height: 'auto' }}
/>
The width attribute is working but still not the height.
And when I try this code :
<img
alt="..."
className="img-fluid floating"
src={Landing1}
width={375}
/>
Nothing is working…
2
Answers
Dont style the element directly, instead wrap it in a element and style it like this:
The hieght is by default auto and try not to set the height of an img element or its parent element because it may change the original aspect ratio of the image.
In react, just use
style = {{height: 300}}
, notstyle = {{height: '300px'}}
, since a number only will represent pixels. Also, check if the parent element is limiting the maximum height.