<div class="wrapper">
<div class="alert">
<p>Your browser doesn't support CSS object-view-box. Please view it in the latest Chrome Canary and allow the "Experimental Web Platform features" flag.</p>
</div>
</div>
<div class="grid">
<div class="item">
<img class="img-0" src="https://i.ibb.co/gjcf8t1/cupcake-2.jpg" alt="">
<p>Original image</p>
</div>
<div class="group">
<div class="item">
<img class="img-1" src="https://i.ibb.co/gjcf8t1/cupcake-2.jpg" alt="">
<p><code>object-view-box: inset(0% 19% -33% 57%)</code></p>
</div>
<div class="item">
<img class="img-2" src="https://i.ibb.co/gjcf8t1/cupcake-2.jpg" alt="">
<p><code>object-view-box: inset(0% 15% -52% 3%)</code></p>
</div>
<div class="item"><img class="img-3" src="https://i.ibb.co/gjcf8t1/cupcake-2.jpg" alt="">
<p><code>object-view-box: inset(0% 0% 17% 0%)</code></p>
</div>
</div>
</div>
img {
width: 220px;
aspect-ratio: 3 / 2;
object-fit: cover;
}
.img-0 {
aspect-ratio: 1 / 2;
}
.img-1 {
object-view-box: inset(0% 19% -33% 57%);
}
.img-2 {
object-view-box: inset(0% 15% -52% 3%);
}
.img-3 {
object-view-box: inset(0% 0% 17% 0%);
}
.group {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 1rem 1.5rem;
}
/* Other styles */
.item {
text-align: center;
margin-bottom: 2rem;
p {
padding: 0.5rem;
}
code {
font-size: 14px;
}
}
.alert {
display: block;
max-width: 70ch;
padding: 1rem;
text-align: center;
margin: 0 auto 1rem;
background-color: #ffeeee;
border: 1px solid red;
border-radius: 5px;
font-size: 0.75rem;
}
@supports (object-view-box: inset(0)) {
.alert {
display: none;
}
}
body {
font-family: "system-ui";
padding: 1rem;
line-height: 1.45;
}
img {
max-width: 100%;
box-shadow: 0 8px 15px 0 rgba(#000, 0.1), 0 2px 5px 0 rgba(#000, 0.2);
border-radius: 12px;
}
*,
*:before,
*:after {
box-sizing: border-box;
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.