Transparent foreground

后端 未结 1 1361
情书的邮戳
情书的邮戳 2021-01-18 21:38

I would like to add a semi-transparent uniform layer as a foreground for a div element. What is the best way to do that?

相关标签:
1条回答
  • 2021-01-18 22:33

    You could use this CSS...

    div.parent {
       position: relative;
    }
    
    /* this div is a descendent of the div above */
    div.child {
       position: absolute;
       top: 0;
       right: 0;
       bottom: 0;
       left: 0;
       opacity: .6;
       background: #fff;
    } 
    

    jsFiddle.

    If you want mouse events to go through this cover, add pointer-events: none to the div.child.

    You tagged it jQuery, so to add this child element via jQuery...

    $('div.parent').append('<div class="child" />');
    
    0 讨论(0)
提交回复
热议问题