Responsive image
To make an image truly responsive, a max-width needs to be set at 100% and height needs to be auto.
This makes the image full width of the parent but maintains the aspect ratio as height is at auto.
Notation:
- You can target the responsive image class by using
img-responsive. This adds the properties outlined above to the element.
Properties:
| Class | Properties |
|---|---|
| .img-responsive | max-width: 100%; height: auto; |
Example:
Here the image is using the img-responsive class to always be 100% of the parent
(image-container). As the height is auto, the
aspect ratio will remain intact.
Go ahead a resize the screen to see the effect
<div class="img-container b-light p-2"> <img class="img-responsive" src="..." alt="Responsive Design"> </div>