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

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

    Opacity will always inherits by the child element regardless whatever the element in there, there is no workaround up to today have suggested, when the moving of the child element outside the transparency background is not an option like in a popup menu/dialog box creation, use of background with the rgba is the solution.

    Here is a input box that i created that i can turn on or off with the class property invisible by javascript

     
    

    CSS

    #blackout {
        z-index: 9999;
        background: rgba(200, 200, 200, 0.6); 
        height: 100%;
        width: 100%;
        display: block;
        padding: 0px;
        clear: both;
        float: left;
        position: absolute;
        margin-top: -10px;
        margin-right: 0px;
        margin-bottom: 0px;
        margin-left: -10px;
    }
    
    #blackout #middlebox {
        border: thick solid #333;
        margin: 0px;
        height: 150px;
        width: 300px;
        background-color: #FFF;
        top: 50%;
        left: 50%;
        position: absolute;
        -ms-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
        padding: 10px 50px 0px 50px;
    
    }
    
    #middlebox p {
        float: left;
        width:100%;
        clear:both;
    }
    
    #middlebox input {
        clear:both;
        margin-bottom:10px;
    }
    
    #middlebox input[type=text]{
        width:100%;
    }
    
    #middlebox input[type=button]{
        float:right;
        width:30%;
    }
    
    .invisible{
        visibility:hidden !important;
    }
    

提交回复
热议问题