Help us understand the problem. What is going on with this article?

CSSで背景画像にぼかし加工と半透明カラー加工を同時に行う

More than 1 year has passed since last update.

はじめに

LPなどでよく使われるやつです。こんな感じの完成イメージです。

スクリーンショット 2017-07-21 3.08.44.png

http://techd.jp/

普段cssを専門に触っているわけではないので、もっと良い方法があればフィードバックください。

実装

::before を使って擬似要素を定義します。

::before (:before)
https://developer.mozilla.org/ja/docs/Web/CSS/::before

例えば、topというクラスを持つdiv要素を対象とする場合、以下のように定義するのがポイントです。

  • top::before
    • カラー
  • top
    • 画像のURL
    • カラーの透明度
    • ぼかし度

htmlとcssのサンプルは以下の通りです。

<div class="top"></div>
.top{
  z-index:0;
  overflow: hidden;
  background-color: rgb(0,163,175);/*半透明カラーの色*/
}
.top::before{
  content: '';
  background: url('../../assets/img/hogehoge.jpg');/*背景画像のURL*/
  opacity: 0.5;/*半透明カラーの透明度*/
  filter: blur(8px);/*ぼかし度*/
  position: absolute;
  /* 参考: http://designcolor-web.com/2016/09/14/css-blur-effects-background/*/
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
  z-index: -1;
}

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away