div css背景顏色半透明 文字不透明兼容ie、火狐等瀏覽器

IE:外層filter,內層position:relative或absolute。html

FF:外層不使用opacity,而用background:rgba()。web


 

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <style>
        #wrapper
        {
            background: #369;
            width:300px;
            height:150px;
        }
        #div1
        {
            -moz-opacity: 0.3; /* FF 3.5如下 */
            opacity: 0.3; /* FF 3.5及以上 */
            filter: alpha(opacity=30); /* IE6及以上 */
            background: #fff;
            width: 200px;
            height: 50px;
        }
        #div2
        {
            background: rgba(255, 255, 255, 0.3) !important; /* IE無效,FF有效 */
            background: #fff;
            filter: alpha(opacity=30);
            width: 200px;
            height: 50px;
        }
        #div2 span
        {
            position: relative;
        }
    </style>
 </head>
<body>

<div id="wrapper">

        <div id="div1">

            <span>圖層背景半透明,字體顏色也半透明</span>

        </div>

        <br />

        <div id="div2">

            <span>圖層背景半透明,字體顏色不半透明</span>

        </div>

    </div>

</body>

</html>
相關文章
相關標籤/搜索