Can I set an opacity only to the background image of a div?

后端 未结 8 1311
轮回少年
轮回少年 2020-11-22 11:09

Let\'s say I have

Hi there

I want to put a background-image and give it an opacit

8条回答
  •  情歌与酒
    2020-11-22 12:07

    I implemented Marcus Ekwall's solution but was able to remove a few things to make it simpler and it still works. Maybe 2017 version of html/css?

    html:

    What is Lorem Ipsum?

    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

    css:

    #content {
      text-align: left;
      width: 75%;
      margin: auto;
      position: relative;
    }
    
    #bg {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background: url('https://static.pexels.com/photos/6644/sea-water-ocean-waves.jpg') center center;
      opacity: .4;
      width: 100%;
      height: 100%;
    }
    

    https://jsfiddle.net/abalter/3te9fjL5/

提交回复
热议问题