Background Transparency with opaque text

Discussion in 'HTML & Website Design' started by secondcreative, Aug 4, 2016.

  1. #1
    I tried searching for a similar thread, but was unable to find anything.

    I'm trying to make the backgrounds of my content divs 70% transparent using the following:

    .transparency {
    filter:alpha(opacity=70);
    -moz-opacity:0.7;
    -khtml-opacity: 0.7;
    opacity: 0.7;
    }

    Unfortunately, this is also making the content within those divs use the same opacity. I tried nesting another div inside using the following:

    .opaque-text {
    filter: alpha(opacity=100);
    -moz-opacity: 1.0;
    -khtml-opacity: 1.0;
    opacity: 1.0;
    position: relative;
    z-index: 2;
    }

    But it does not seem to be working. I feel like this should be a simple fix, and I'm missing something obvious. I know I can always use a .png as a background image, but I'm trying to do this in pure CSS if at all possible.

    Thanks!
     
    Last edited: Aug 4, 2016
    secondcreative, Aug 4, 2016 IP
  2. Ian08

    Ian08 Well-Known Member

    Messages:
    93
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    108
    #2
    Child elements are unable to be opaque when the parent element is translucent.

    You could use a pseudo element to contain the background image, and then position the pseudo element and make it translucent.


    == EDIT ==
    Deleted my above reply text because I misunderstood the OP.
     
    Last edited: Aug 5, 2016
    Ian08, Aug 4, 2016 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Or, just use background-color with rgba() - rgb with transparency option. rgba(0,0,0,0.5) will be black with 50% transparency (ergo, grey).

    Opacity is a bad choice.
     
    PoPSiCLe, Aug 5, 2016 IP
  4. Ian08

    Ian08 Well-Known Member

    Messages:
    93
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    108
    #4
    Well... what PoPSiCLe says.

    I didn't read your original post carefully and thought you wanted a translucent background image. My bad. If what you want is a translucent background color, then simply use rgba.
     
    Ian08, Aug 5, 2016 IP