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

前端 未结 12 2357
臣服心动
臣服心动 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:19

    Use such elements that you can add :before or :after. My solution

    Inside of container element is not effected by opacity.

    Css.

    .container{
        position: relative;
    }
    
    .container::before{
        content: '';
        height: 100%;
        width: 100%;
        position: absolute;
        background-color: #000000;
        opacity: .25
    }
    

提交回复
热议问题