Home  >  Article  >  Web Front-end  >  CSS achieves transparent background and opaque text (compatible with all browsers)_html/css_WEB-ITnose

CSS achieves transparent background and opaque text (compatible with all browsers)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:56:18980browse

In newer browsers such as FF/Chrome, you can use the rgba of the css attribute background-color to easily achieve background transparency while the text remains opaque. IE6/7/8 browsers do not support rgba, and can only be achieved by using IE's exclusive filter filter:Alpha. However, this way of writing will also make the text transparent, so it can only be used within the child nodes of the transparent container (except text nodes). Set position: relative to not inherit the transparency filter of its parent element. The code is as follows:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  2 <html xmlns="http://www.w3.org/1999/xhtml">  3 <head>  4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  5 <title>Web开发者网络 - www.admin10000.com</title>  6 <style type="text/css"> 7 .warp{ background:#eee url(back.jpg) no-repeat left top; width:440px;height:400px;    border:1px solid #ccc;} 8 .content { width:180px; height:260px; margin:0px auto; padding:30px 30px;background:rgba(255, 255, 255, 0.6)!important; 9 filter:Alpha(opacity=60); background:#fff; /* 使用IE专属滤镜实现IE背景透明*/ }10 .content p{ position:relative;} /*实现IE文字不透明*/ 11 </style> 12 </head> 13 <body> 14 <div class="warp"> 15 <div class="content"><p>Admin10000.com 是WEB开发者学习交流必备网站。Admin10000.com 是WEB开发者学习交流必备网站。Admin10000.com 是WEB开发者学习交流必备网站。Admin10000.com 是WEB开发者学习交流必备网站。Admin10000.com 是WEB开发者学习交流必备网站。Admin10000.com 是WEB开发者学习交流必备网站。</p></div> 16 </div> 17 </body> 18 </html> 

The above code is in IE6.0 /FF3.0 / Opera10/Chrome/Safari all passed the test

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn