CSS: preserve aspect ratio image css Example


CSS Example: This is the "preserve aspect ratio image css" Example. compiled from many sources on the internet by SimpleTutorials.org

keep aspect ratio of image css

img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;

css keep image ratio

img {
  object-fit: cover;
  width: 100px;

preserve aspect ratio image css

/* Simply add width without height,
aspect ratio will be maintained 
and height will be calculated accordingly*/

img {
  width: 100px;

css keep aspect ratio image

.image-full {
    background: url(...some image...) no-repeat;
    background-size: cover;
    background-position: center center;

* Summary: This "preserve aspect ratio image css" CSS Example is compiled from the internet. If you have any questions, please leave a comment. Thank you!