<div class="wrap">
<div class="item">
<h2>未指定</h2>
<img src="https://picsum.photos/350/500" class="cover" />
</div>
<div class="item">
<h2>横幅だけ指定</h2>
<img src="https://picsum.photos/350/500" class="cover item01" />
</div>
<div class="item">
<h2>高さだけ指定</h2>
<img src="https://picsum.photos/350/500" class="cover item02" />
</div>
<div class="item">
<h2>横幅・高さ指定</h2>
<img src="https://picsum.photos/350/500" class="cover item03" />
</div>
</div>
.wrap {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
h2 {
font-size: 16px;
}
img {
background: #d7eef2;
border: 1px solid #aaa;
}
.cover {
object-fit: cover;
}
.item01{
width:100px;
}
.item02{
height:100px;
}
.item03{
width:100px;
height:100px;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.