Cross-Browser CSS Opacity

The ability to make a div element opaque using CSS is useful for creating aseptically pleasing websites and effects. The following code can be used on any CSS element.

Cross-Browser Code

filter: alpha(opacity=50);
-khtml-opacity: 0.5;
-moz-opacity: 0.5;
opacity: 0.5;

Working ExampleIn this example a div element (.box) is centered on the screen using the margin auto code. It is then told its size, width and background color. Finally the element is told to be transparent in IE, Firefox Safari and Konqueror using the code depicted above.

HTML code

<div class= "box"></div>

CSS code

.box {
margin: 0 auto 0 auto;
width: 100px;
height: 100px;
background-color:#000;
filter: alpha(opacity=50);
-khtml-opacity: 0.5;
-moz-opacity: 0.5;
opacity: 0.5;
}
Post Info
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 3.50 out of 5)
Loading ... Loading ...
Leave a Comment

NOTE: When posting a comment please do not paste in large blocks of code. Instead paste your code here and link to it in your comment. Thanks.

Browse by Category

Browse by Year

Credits