Set opacity of background image without affecting child elements

前端 未结 15 2185
闹比i
闹比i 2020-11-22 01:39

Is it possible to set the opacity of a background image without affecting the opacity of child elements?

Example

All links in the footer need a custom bull

15条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 02:22

    You can use CSS linear-gradient() with rgba().

    div {
      width: 300px;
      height: 200px;
      background: linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,.5)), url("https://i.imgur.com/xnh5x47.jpg");
    }
    span {
      background: black;
      color: white;
    }
    Hello world.

提交回复
热议问题