The object-fit property defines how content of a replaced element (e.g., a video or an image) is made to fit the dimensions of its containing box.
Overview tablefill
objectFit
object-fit: contain
object-fit: cover
object-fit: fill
object-fit: none
object-fit: scale-down
Five simple img elements.
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Object-fit example</title>
<link href="content-fit.css" type="text/css" rel="stylesheet">
</head>
<body>
<img src="/logo/wplogo_pillow_wide_tan.png"
alt="Webplatform Logo" class="fill"/>
<img src="/logo/wplogo_pillow_wide_tan.png"
alt="Webplatform Logo" class="contain"/>
<img src="/logo/wplogo_pillow_wide_tan.png"
alt="Webplatform Logo" class="cover"/>
<img src="/logo/wplogo_pillow_wide_tan.png"
alt="Webplatform Logo" class="none"/>
<img src="/logo/wplogo_pillow_wide_tan.png"
alt="Webplatform Logo" class="scale-down"/>
</body>
</html>
All five images are forced to 150x100 pixels, different from both the original size of the image (196x77 pixel) and its aspect ratio.
img {
float: left;
width: 150px;
height: 100px;
border: 1px solid #000;
margin-right: 1em;
}
.fill {
object-fit: fill;
}
.contain {
object-fit: contain;
}
.cover {
object-fit: cover;
}
.none {
object-fit: none;
}
.scale-down {
object-fit: scale-down;
}
Related specifications
object-fit
object-fit
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4