画面サイズの変更によって、3列から1列3行のレイアウトに変化します。
デモ
See the Pen layout 2 by logsuke (@design-list) on CodePen.
コード
<section>
<div class="section-container">
<div class="bg content-1">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</div>
</section>
* {
margin: 0;
padding: 0;
box-sizing: border-box
}
/* 変数を定義 */
:root {
--nav-height: 8rem;
--max-width: 1024px;
--container-padding: 0 4rem;
--gap: 2rem;
}
/* section */
.section-container {
width: 100%;
/* 変数を使用 */
max-width: var(--max-width);
margin: 0 auto;
}
.bg {
border: 5px solid rgb(55, 53, 53);
position: relative;
opacity: 0.5;
background-image: radial-gradient(#e331dd 2px, #e5e5f7 2px);
background-size: 40px 40px;
}
.content-1 {
display: flex;
gap: var(--gap);
padding: 1rem;
position: relative;
justify-content: center;
}
.item {
width: 25%;
height: 400px;
background: rgba(233, 181, 255, 0.608);
position: relative;
}
.item::before {
content: 'item';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: black;
font-size: 2rem;
}
/* 768pxで縦並び */
@media screen and (max-width: 768px) {
.content-1 {
flex-direction: column;
}
.item {
width: 100%;
}
}