CSS cross browser opacity example

Hello,

While I am working on a project one of the requirement is that make the site look and feel as much compatible with Internet Explorer 7.

IE7 Yeah! Well nothing against the browser because its Free and still lot of people use it. I myself am not fan of IE7 but IE9 and 10 are on right track I guess. I am Chrome lover.

Anyway this post is not about the browser comparison but rather I just wanted to highlight how we can make the element opacity to work in majority of the browsers.

Alright so lets check it out.

For the example I worked on below is the mark up used

The Markup

  1. <div class="outer">
  2.       <img src="http://jaspreetchahal.org/examples/img/demopill.png">
  3.      <d iv class="inner with-opacity">
  4.            Copyright &copy; jaspreetchahal.org 
  5.      </div>
  6. </div>

 

I wanted to display an overlay on my image with text “Copyright &copy; jaspreetchahal.org

lets check the CSS for the above

  1. .outer {
  2. position: relative;
  3. border:5px #000 solid;
  4. border-radius: 10px;
  5. width:400px;
  6. text-align: center;
  7. color:#fff;
  8. }
  9. .inner {
  10. position: absolute;
  11. left:0;
  12. right:0;
  13. top: 40%;
  14. font-size: 22px;
  15. background: #fff;
  16. color: #000;
  17.  
  18. }
  19. .with-opacity {
  20.  
  21. /* all modern browsers */
  22. opacity: 0.3;
  23.  
  24. /*if above property is supported then all the below will be skipped*/
  25. /* Internet explorer 8 */
  26. -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
  27.  
  28. /* for internet explorer 5 to 7 */
  29. filter: alpha(opacity=30);
  30.  
  31. /* Mozilla */
  32. -moz-opacity: 0.3;
  33.  
  34. /* Safari 1.x */
  35. -khtml-opacity: 0.3;
  36.  
  37. }

All the major browsers now support property opacity but this was not the case some time back. But still if you are looking to make your website to work on many old browsers that some people still use then making use of browser specific CSS properties is the right thing to do as we did with the opacity property above

Lets check the result of the above styles

Demo

Demo can be viewed by click the link below.

http://jaspreetchahal.org/examples/css-examples/cross-browser-element-opacity.html

I hope that this will help you in one way or another

Cheers

Advertisement

 

 

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Speak Your Mind

*

CommentLuv badge