treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] CSS Opacity for certain Divs

  • Aloha!

    I'm kinda new here, and this is my first question...

    For CSS, how can I make it so that a certain background of a div id has a certain opacity (like 0 is nothing and 1 is a solid color background). I have an image as a background for the website (don't worry, it works with the design), and would like to do this in order to give it a nice look/

    Thanks!
  • You can change an entire div's opacity with CSS, but I'm not sure about just the background image. If it was a color or gradient you could do it with CSS.

    For CSS opacity on a div of 50%:

    div { opacity: .5; }


    For 50% opacity of a div on a black background:

    div { background: rgba(0,0,0,.5); }


    You can do gradients with browser extensions currently. http://css-tricks.com/css3-gradients/
  • .transparent50 {
    background: rgba(255, 255, 255, 0.5);
    }
    .transparent100 {
    background: rgba(255, 255, 255, 1);
    }


    Then just use
    <div class="post transparent50">...</div>
    etc

    Ps: sorry about the abruptness, in on my phone.
  • Thanks you guys!


    This is awesome

    Exactly what I was looking for