Resetting the opacity of a child element - Maple Browser (Samsung TV App)

后端 未结 3 1452
鱼传尺愫
鱼传尺愫 2020-11-30 01:55

I have an issue with creating a transparent element which has a child element. Using this code the child element gets the opacity value from the parent element.

I ne

3条回答
  •  独厮守ぢ
    2020-11-30 02:09

    The problem you probably have (based on looking at your selectors) is that opacity affects all child elements of a parent:

    div
    {
        background: #000;
        opacity: .4;
        padding: 20px;
    }
    
    p
    {
        background: #f00;
        opacity: 1;
    }​
    

    http://jsfiddle.net/Kyle_/TK8Lq/

    But there is a solution! Use rgba background values and you can have transparency wherever you want :)

    div
    {
        background: rgba(0, 0, 0, 0.4);
        /*opacity: .4;*/
        padding: 20px;
    }
    
    p
    {
        background: rgba(255, 0, 0, 1);
        /*opacity: 1;*/
    }​
    

    http://jsfiddle.net/Kyle_/TK8Lq/1/


    For text, you can just use the same rgba code, but set to the color property of CSS:

    color: rgba(255, 255, 255, 1);
    

    But you must use rgba on everything for this to work, you have to remove the opacity for all parent elements.

    http://jsfiddle.net/Kyle_/TK8Lq/2/

提交回复
热议问题