CSS3 opacity属性
作用:检索或设置对象的不通明度。
语法:
opacity: value|inherit;
value:划定不通明度。从 0.0 (完整通明)到 1.0(完整不通明)。
inherit:应当从父元素继续 opacity 属性的值。
申明:关于尚不支撑opacity属性的IE浏览器能够运用IE私有的滤镜属性来完成与opacity雷同的结果。
CSS3 opacity属性的运用示例
示例1:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style> h1 { margin: 10px 0; font-size: 16px; } .test, .test2 { width: 300px; height: 150px; padding: 10px; } .test { background:#050; } .test2 { margin: -120px 0 0 50px; background: #000; filter: alpha(opacity=50); opacity: .5; color: #fff; } </style> </head> <body> <h1>下例是一个半通明的结果:</h1> <div>不通明度为100%的box</div> <div>不通明度为50%的box</div> </body> </html>
结果图:
示例2:运用 JavaScript 来转变元素的不通明度。
<!DOCTYPE html> <html> <meta charset="UTF-8"> <head> <style> .demo{ width: 450px; height: 200px; background-color: red; margin: 10px 0px; } </style> <script> function ChangeOpacity(x) { // 返回被选选项的文本 var opacity=x.options[x.selectedIndex].text; var el=document.getElementById("box"); if (el.style.opacity!==undefined) {el.style.opacity=opacity;} else {alert("Your browser doesn't support this example!");} } </script> </head> <body> <p id="p1">请从下面的例子中挑选一个值,以转变此元素的不通明度。</p> <div id="box" class="demo"></div> <select onchange="ChangeOpacity(this);" size="5"> <option />0 <option />0.2 <option />0.5 <option />0.8 <option selected="selected" />1 </select> </body>
结果图:
以上就是本篇文章的全部内容,愿望能对人人的进修有所协助。更多精彩内容人人能够关注ki4网相干教程栏目!!!
以上就是opacity属性怎样用的细致内容,更多请关注ki4网别的相干文章!