0

I have this code

    body {
        background-color: #808080;
        background-image: url('/Content/img/emboss.png');
        background-repeat: no-repeat;
        background-position: center 250px;
        font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
        font-size: 10pt;
        opacity: 0.8;
    }
    img {
        opacity: 1;
    }

However it doesn't work. The entire site, every element has an opacity of 0.8 which is what I want and it looks perfect. However when rendering an image I don't want any transparency.

How would I go about doing this in my css

Dale Fraser
  • 4,623
  • 7
  • 39
  • 76

2 Answers2

2

You can achieve this using little trick. Use :not pseudo selector like below.

 body {
    background-color:#808080;
    background-image: url('/Content/img/emboss.png');
    background-repeat: no-repeat;
    background-position: center 250px;
    font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
    font-size: 10pt;
   }
   body :not(img)
   {
    opacity:0.7;
   }

DEMO

Suresh Ponnukalai
  • 13,820
  • 5
  • 34
  • 54
0

You cannot use opacity property for this kind of effect. Rather create a div over the body and keep its background color as rgba (255,255,255,0.8) and then add image inside that div.

Changing alpha values is the only way of separating the opacity of a parent to its child.

aayush
  • 26
  • 1
  • 5