Basic CSS - how to overlay a DIV with semi-transparent DIV on top

前端 未结 5 1401
我寻月下人不归
我寻月下人不归 2020-12-04 17:43

I\'m struggling to make this render right in my browser (Chrome). I have a wrapper holding all the elements of the HTML, and I want to have a DIV (lets call it div-1) that h

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 18:03

    Here's a pure CSS solution, similar to DarkBee's answer, but without the need for an extra .wrapper div:

    .dimmed {
      position: relative;
    }
    
    .dimmed:after {
      content: " ";
      z-index: 10;
      display: block;
      position: absolute;
      height: 100%;
      top: 0;
      left: 0;
      right: 0;
      background: rgba(0, 0, 0, 0.5);
    }
    

    I'm using rgba here, but of course you can use other transparency methods if you like.

提交回复
热议问题