Have a child opacity different then parent opacity with CSS

后端 未结 5 1197
花落未央
花落未央 2021-01-20 11:10

Here are my box classes

.rectangle-box {
    width: 200px;
    height: 30px;
    background: #808080;
    opacity: 0.3;
    float: right;
}

.re         


        
5条回答
  •  孤城傲影
    2021-01-20 11:48

    Use RGBA instead of hex. using opacity: affects child elements and rgba does not

    .rectangle-box {
            width: 200px;
            height: 30px;
            background-color: rgba(128,128,128, 0.3);
            float: right;
    
        }
    
        .rectangle-red {
            width: 65px;
            height: 30px;
            background-color: rgba(255,71,66, 1);
          float: left;
        } 
    

提交回复
热议问题