How do I mantain original image ratio?
If I have a "img" element and I do "style="width: 25px; height: auto;"" the image doesn't have automatic height, it is modified. How do I get auto height?
How do I mantain original image ratio?
If I have a "img" element and I do "style="width: 25px; height: auto;"" the image doesn't have automatic height, it is modified. How do I get auto height?
The width
and height
properties of img
tags do this by default.
<img width="100" src="https://images.unsplash.com/photo-1562939230-e05e7c80c1d5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=652&q=80" />
<hr />
<img width="25" src="https://images.unsplash.com/photo-1562939230-e05e7c80c1d5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=652&q=80" />
You can use the code given below.
#one {
width: 25%;
height: auto:
}
#two {
width: 20%;
height: auto:
}
<img id="one" src="https://picsum.photos/id/237/120/180" />
<img id="two" src="https://picsum.photos/id/237/120/180" />