how to handle 'double opacity' of two overlapping divs

前端 未结 5 1162
时光取名叫无心
时光取名叫无心 2021-01-23 16:19

I have two divs, both with 0.6 opacity. I need them to overlap but retain their opacity and not create a new combined opacity level. I can\'t use an image.

EDIT -- The

5条回答
  •  日久生厌
    2021-01-23 17:07

    I have created a Q/A to handle this scenario along with the 'hover' of such overlapped elements.

    Overlapped elements with opacity and handling the 'hover' on those.

    The solution is basically to set the opacity in the parent level instead directly on the children elements and to toggle those while hover, with JS.


    HTML


    JS

    $(".first, .second").hover(function() {
      $(".wrapper, .first, .second").not(this).toggleClass("add-opacity");
    });
    

    CODEPEN

    Hope this helps.

提交回复
热议问题