2
1

More than 3 years have passed since last update.

背景画像のみを透過する方法

Last updated at Posted at 2020-06-06

プログラミングの勉強日記

2020年6月6日 Progate Lv.83
ウェブページ制作中
背景画像を透過させたいのに、すべての要素が透過されてしまった。

opacityを背景画像のみに適用する

html
<div class="backgroundImage">
  <h1>背景画像だけにopacityを適用</h1>
</div>
css
.backgroundImage{
  background-image:url("./photo/image.png");
  opacity:0.4;
}

 このように指定すると、<h1>にまでopacityが適用してしまう。そこで、 背景画像の上にrgbaを置いて背景画像だけを透過させるように見せる。

html
<div class="backgroundImage">
  <div class="tentativeImage>
    <h1>背景画像だけにopacityを適用</h1>
  </div>
</div>
css
.backgroundImage{
  background-image:url("./photo/image.png");
}
.tentativeImage{
    /* 背景画像の上にrgbaを置いて背景画像のみを透過させる */
    background: rgba(255,255,255,0.5); 
}
2
1
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
2
1