d
Amit DhamuSoftware Engineer
 

Maintain Aspect Ratio

1 minute read 00000 views

Sometimes, you need to scale an image in CSS and you set a width or max width and you ignore the height. To maintain that the height is in proportion to the width:

.container img {
  max-width: 300px;
  height: auto;
}