今回は、セクションの区切りを曲線にする方法について紹介します。
例えば、たけだ税理士事務所さんのWebサイトでよく使われています。
【CSS】セクションの区切りを曲線にする方法
完成形はこちら。
HTML
<section class="section">
<div class="bg-top"></div>
<div class="content">
<div class="inner">
<h2>セクションの上部が曲線です</h2>
<p>ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。</p>
</div>
</div>
</section>
<section class="section section-bottom">
<div class="content">
<div class="inner">
<h2>セクションの下部が曲線です</h2>
<p>ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。</p>
</div>
</div>
<div class="bg-bottom"></div>
</section>
<section class="section">
<div class="bg-top"></div>
<div class="content">
<div class="inner">
<h2>セクションの上部が曲線です</h2>
<p>ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。</p>
</div>
</div>
</section>
<section class="section section-bottom">
<div class="content">
<div class="inner">
<h2>セクションの下部が曲線です</h2>
<p>ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。</p>
</div>
</div>
<div class="bg-bottom"></div>
</section>
<section class="section"> <div class="bg-top"></div> <div class="content"> <div class="inner"> <h2>セクションの上部が曲線です</h2> <p>ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。</p> </div> </div> </section> <section class="section section-bottom"> <div class="content"> <div class="inner"> <h2>セクションの下部が曲線です</h2> <p>ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。ダミーテキストです。</p> </div> </div> <div class="bg-bottom"></div> </section>
CSS
.section {
margin: 50px 0;
}
.section-bottom .content .inner {
padding: 100px 0 0 0;
}
.bg-top {
overflow: hidden;
position: relative;
width: 100%;
height: 120px;
}
.bg-top::before {
display: block;
content: "";
position: absolute;
top: 0;
left: 50%;
z-index: -1;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
width: 400vw;
height: 500vw;
border-radius: 100%;
background-color: #f9f6f0;
}
.content {
background-color: #f9f6f0;
text-align: center;
}
.content .inner {
max-width: 1000px;
margin: 0 auto;
width: calc(100% - 40px);
padding-bottom: 100px;
}
.content .inner h2 {
font-size: 25px;
}
.content .inner p {
font-size: 16px;
line-height: 1.5;
margin-top: 25px;
}
.bg-bottom {
overflow: hidden;
position: relative;
width: 100%;
height: 120px;
}
.bg-bottom::before {
display: block;
content: "";
position: absolute;
bottom: 0;
left: 50%;
z-index: -1;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
width: 400vw;
height: 500vw;
border-radius: 100%;
background-color: #f9f6f0;
}
.section {
margin: 50px 0;
}
.section-bottom .content .inner {
padding: 100px 0 0 0;
}
.bg-top {
overflow: hidden;
position: relative;
width: 100%;
height: 120px;
}
.bg-top::before {
display: block;
content: "";
position: absolute;
top: 0;
left: 50%;
z-index: -1;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
width: 400vw;
height: 500vw;
border-radius: 100%;
background-color: #f9f6f0;
}
.content {
background-color: #f9f6f0;
text-align: center;
}
.content .inner {
max-width: 1000px;
margin: 0 auto;
width: calc(100% - 40px);
padding-bottom: 100px;
}
.content .inner h2 {
font-size: 25px;
}
.content .inner p {
font-size: 16px;
line-height: 1.5;
margin-top: 25px;
}
.bg-bottom {
overflow: hidden;
position: relative;
width: 100%;
height: 120px;
}
.bg-bottom::before {
display: block;
content: "";
position: absolute;
bottom: 0;
left: 50%;
z-index: -1;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
width: 400vw;
height: 500vw;
border-radius: 100%;
background-color: #f9f6f0;
}
.section { margin: 50px 0; } .section-bottom .content .inner { padding: 100px 0 0 0; } .bg-top { overflow: hidden; position: relative; width: 100%; height: 120px; } .bg-top::before { display: block; content: ""; position: absolute; top: 0; left: 50%; z-index: -1; -webkit-transform: translateX(-50%); transform: translateX(-50%); width: 400vw; height: 500vw; border-radius: 100%; background-color: #f9f6f0; } .content { background-color: #f9f6f0; text-align: center; } .content .inner { max-width: 1000px; margin: 0 auto; width: calc(100% - 40px); padding-bottom: 100px; } .content .inner h2 { font-size: 25px; } .content .inner p { font-size: 16px; line-height: 1.5; margin-top: 25px; } .bg-bottom { overflow: hidden; position: relative; width: 100%; height: 120px; } .bg-bottom::before { display: block; content: ""; position: absolute; bottom: 0; left: 50%; z-index: -1; -webkit-transform: translateX(-50%); transform: translateX(-50%); width: 400vw; height: 500vw; border-radius: 100%; background-color: #f9f6f0; }
まとめ
以上が、セクションの区切りを曲線にする方法でした。