object-fit: scale-down

Only object-fit: scale-down

by Abhijeet Deshmukh

HTML

<div class="original-image">
    <p>original image</p>
    <img src="http://www.menucool.com/slider/jsImgSlider/images/image-slider-2.jpg">
</div>
<div class="image">
    <p>object-fit: scale-down</p>
    <img class="object-fit_scale-down" src="http://www.menucool.com/slider/jsImgSlider/images/image-slider-2.jpg">
</div>
<div style="border:1px solid maroon;margin:30px"></div>
<div class="original-image">
    <p>original image</p>
    <img src="http://mattermatters.com/images/small_facebook_icon.png">
</div>
<div class="image">
    <p>object-fit: scale-down</p>
    <img class="object-fit_scale-down" src="http://mattermatters.com/images/small_facebook_icon.png">
</div>

CSS

.object-fit_scale-down {
    /*
    fill: this is the default value which stretches the image to fit the content box, regardless of its aspect-ratio.
    contain: increases or decreases the size of the image to fill the box whilst preserving its aspect-ratio.
    cover: the image will fill the height and width of its box, once again maintaining its aspect ratio but often cropping the image in the process.
    none: image will ignore the height and width of the parent and retain its original size.
    scale-down: the image will compare the difference between none and contain in order to find the smallest concrete object size.
    */
    -o-object-fit: scale-down;
    object-fit: scale-down;
}
.image {
    width: 40%;
}
img {
    height: 200px;
    background-color: gray;
}
img[class] {
    width: 100%;
}
body {
    font-family: Helvetica;
}
p {
    font-weight: 200;
    font-size: 13px;
    margin-bottom: 10px;
    margin-top: 0;
}
.original-image {
    margin-bottom: 50px;
}