【CSS】背景画像を固定したおしゃれなLP(ランディングページ)を作ってみよう
- 更新
- デザインのメモ


ランディングページを作るのですか?

ちょっと作ってみましょうー
実装サンプル
コードを見る(HTML・CSS)
HTML
<main>
<section>
<div class="onebox">
<p>パ</p>
</div>
</section>
<section>
<div class="onebox">
<p>ン</p>
</div>
</section>
<section>
<div class="onebox">
<p>を</p>
</div>
</section>
<section>
<div class="onebox">
<p>食</p>
</div>
</section>
<section>
<div class="onebox">
<p>べ</p>
</div>
</section>
<section>
<div class="onebox">
<p>た</p>
</div>
</section>
<section>
<div class="onebox">
<p>よ</p>
</div>
</section>
<section>
<div class="onebox">
<h1>パンを食べたよ</h1>
</div>
</section>
</main>
<div class="bg"></div>
CSS
背景を固定するのに必要なCSSは『.bg』のところだけです。
/* 背景を固定する(必要なのはここだけ) */
.bg {
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
height: 100vh;
background-image: url("https://125naroom.com/demo/common/img/slide01.svg");
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
opacity: .5;
z-index: -1;
}
/* その上を流れるまる(見た目。なくても背景は固定されます) */
section {
margin: 200px 0;
}
.onebox {
display: flex;
align-items: center;
justify-content: center;
width: 400px;
height: 400px;
margin: 0 auto;
padding: 20px;
background: #ffffff;
text-align: center;
border-radius: 50%;
}
.onebox p {
font-size: 150px;
font-weight: bold;
line-height: 1;
margin: 0;
}
.onebox h1 {
font-size: 22px;
line-height: 2.0;
margin: 0;
}
@media screen and (max-width: 767px) {
.onebox {
width: 250px;
height: 250px;
}
.onebox p {
font-size: 100px;
}
.onebox h1 {
font-size: 16px;
}
}
さいごに

パン柄の服がほしいですー

おしゃれですねー



