How to apply an opacity without affecting a child element with html/css?

前端 未结 12 2316
臣服心动
臣服心动 2020-11-29 04:12

I want to achieve this using html and css:

\"schema\"

I have tried to set the opacity of the container

12条回答
  •  情歌与酒
    2020-11-29 04:16

    Try using rgba as a 'pre content' overlay to your image, its a good way to keep things responsive and for none of the other elements to be effected.

    header #inner_header_post_thumb {
      background-position: center;
      background-size: cover;
      position: relative;
      background-image: url(https://images.pexels.com/photos/730480/pexels-photo-730480.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb);
      border-bottom: 4px solid #222;
    }
    
    header #inner_header_post_thumb .dark_overlay {
      position: relative;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      background-color: rgba(0, 0, 0, 0.75);
    }
    
    header #inner_header_post_thumb .dark_overlay .container .header-txt {
      padding-top: 220px;
      padding-bottom: 220px;
      color: #ffffff;
      text-align:center;
    }
    
    header #inner_header_post_thumb .dark_overlay .container .header-txt h1 {
      font-size: 40px;
      color: #ffffff;
    }
    
    header #inner_header_post_thumb .dark_overlay .container .header-txt h3 {
      font-size: 24px;
      color: #ffffff;
      font-weight: 300;
    }
    
    header #inner_header_post_thumb .dark_overlay .container .header-txt p {
      font-size: 18px;
      font-weight: 300;
    }
    
    header #inner_header_post_thumb .dark_overlay .container .header-txt p strong {
      font-weight: 700;
    }

    Title On Dark A Underlay

    Have a dark background image overlay without affecting other elements

    No longer any need to re-save backgrounds as .png ... Awesome

    See a working codepen here

提交回复
热议问题