tags:

views:

46

answers:

2

Hello, is there a way to achieve this effect in a cross-browser compatible way without having to prepare separated images?

Basically the frame on which text lays has a white overlay of 50% opacity.. I would like a solution that doesn't involve creating any other image in addition to the background but I don't know if it's possible!

alt text

+4  A: 

Try RGBA, e.g.

div { background-color: rgba(255, 255, 255, 0.5); }

As always, this won't work in every single browser ever written.

Bobby Jack
works but it's not compatible with IE, so I had to use a background image of 1 pixel with 50% alpha. Thanks anyway :)
Jack
+1  A: 

If you can't use rgba due to browser support, and you don't want to include a semi-transparent white PNG, you will have to create two positioned elements. One for the white box, with opacity, and one for the overlaid text, solid.

<head>
    <style type="text/css">

        body { background: red; }

        .box { position: relative; z-index: 1; }
        .box .back {
            position: absolute; z-index: 1;
            top: 0; left: 0; width: 100%; height: 100%;
            background: white; opacity: 0.75;
        }
        .box .text { position: relative; z-index: 2; }

        body.browser-ie8 .box .back { filter: alpha(opacity=75); }

    </style>
</head>
<!--[if lt IE 9]><body class="browser-ie8"><![endif]-->
<!--[if gte IE 9]><!--><body><!--<![endif]-->

    <div class="box">
        <div class="back"></div>
        <div class="text">
            Lorem ipsum dolor sit amet blah blah boogley woogley oo.
        </div>
    </div>

</body>
bobince