If you set the opacity of an element, it applies to all the elements it contains. You can give them an opacity as well, but it will be relative between 0 and the parent's opacity, as you can see here:
http://jsfiddle.net/hLw2c/
In other words, it's not possible to do it like this:
<div class="outer">YO<div class="inner">Zippazip</div></div>
.outer {
opacity: 0.5;
background-color: red;
}
.inner {
opacity: 1;
background-color: blue;
}
One possible workaround is to use a pseudo element to fake the background, like this:
http://jsfiddle.net/hLw2c/1/
<div class="outer">YO<div class="inner">Zippazip</div></div>
.outer {
position: relative;
}
.outer:before {
position: absolute;
display: block;
content: "";
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0.3;
background-color: red;
z-index: -1;
}
.inner {
opacity: 1;
background-color: blue;
}
Now, the header itself is fully opaque and doesn't have a background. The background is made by the :before
pseudo element. This can be half transparent without affecting the other content of the header, because that content is not inside the pseudo element.