8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CSS:背景の一部をぼかす表現

Posted at

See the Pen Frosted glass background by Kazuyoshi Goto (@KazuyoshiGoto) on CodePen.

テキストの乗っているレイヤーを、擦りガラスで透かしたような表現を作っています。

CSS(Sass)

HTMLはごくシンプルなのでCSSの要点箇所について。

body, section:before {
  background:url("***.jpg");
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
}
section:before {
  content: "";
  z-index: -1;
  -webkit-filter: blur(4px);
  -ms-filter: blur(4px);
  filter: blur(4px);
  position: absolute;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

まず bodysection:before に同一の背景画像を設定しています。

次に section:before のみにCSSフィルター filter:blur を設定しぼかしています。

section ではなく section:before に背景を設定しているのが要です。

sectionblur を設定するとテキストなど中の要素すべてがぼけてしまうため、 section:before にぼかした背景を設定し section 本体の後ろに重ねる形にする手法で実現しています。

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?