<h2>Flexboxの限界</h2>
<div class="container">
<div class="list--flex">
<a href="" class="list--item">
<div class="list--item__image" style="background-image: url('http://placekitten.com/200/300');">
</div>
<div class="list--item__text">
<h3>私の好きなおやつ</h3>
<p>にゃんぽこら</p>
</div>
</a>
<a href="" class="list--item">
<div class="list--item__image" style="background-image: url('http://placekitten.com/200/300');">
</div>
<div class="list--item__text">
<h3>私の好きなおやつ</h3>
<p>にゃんぽこら</p>
</div>
</a>
<a href="" class="list--item">
<div class="list--item__image" style="background-image: url('http://placekitten.com/200/300');">
</div>
<div class="list--item__text">
<h3>私の好きなおやつ</h3>
<p>にゃんぽこら</p>
</div>
</a>
<a href="" class="list--item">
<div class="list--item__image" style="background-image: url('http://placekitten.com/200/300');">
</div>
<div class="list--item__text">
<h3>私の好きなおやつ</h3>
<p>にゃんぽこら</p>
</div>
</a>
</div>
</div>
<h2>Gridの場合</h2>
<div class="container">
<div class="list--grid">
<a href="" class="list--item">
<div class="list--item__image" style="background-image: url('http://placekitten.com/200/300');">
</div>
<div class="list--item__text">
<h3>私の好きなおやつ</h3>
<p>にゃんぽこら</p>
</div>
</a>
<a href="" class="list--item">
<div class="list--item__image" style="background-image: url('http://placekitten.com/200/300');">
</div>
<div class="list--item__text">
<h3>私の好きなおやつ</h3>
<p>にゃんぽこら</p>
</div>
</a>
<a href="" class="list--item">
<div class="list--item__image" style="background-image: url('http://placekitten.com/200/300');">
</div>
<div class="list--item__text">
<h3>私の好きなおやつ</h3>
<p>にゃんぽこら</p>
</div>
</a>
<a href="" class="list--item">
<div class="list--item__image" style="background-image: url('http://placekitten.com/200/300');">
</div>
<div class="list--item__text">
<h3>私の好きなおやつ</h3>
<p>にゃんぽこら</p>
</div>
</a>
</div>
</div>
h2 {
text-align: center;
}
.list {
&--flex {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
align-items: flex-start;
align-content: space-around;
gap: 25px;
max-width: 955px;
margin: 0 auto;
}
&--item {
display: block;
max-width: 220px;
min-height: 290px;
border-radius: 10px;
background: #fff;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.16);
filter: drop-shadow(0px 0px 10px rgba(0, 0, 0, 0.16));
padding: 25px 18px 23px 23px;
&__image {
width: 130px;
height: 130px;
border-radius: 50%;
background-position: center;
background-size: cover;
margin: 0 auto 15px auto;
}
&__text {
h3 {
font-weight: bold;
line-height: 1.57;
text-align: left;
color: #3e3a39;
margin-bottom: 6px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
p {
font-weight: normal;
line-height: 1.3;
text-align: left;
color: #3e3a39;
}
}
}
}
.list--grid {
display: grid;
grid-template-columns: repeat(auto-fit, 220px);
justify-content: center;
grid-gap: 25px;
}
View Compiled
This Pen doesn't use any external JavaScript resources.