zoukankan      html  css  js  c++  java
  • css怎么样设置透明度?

    css怎么样设置透明度?下面本篇文章就来给大家介绍一下使用css设置透明度的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

    在CSS中想要设置透明度,可以使用opacity属性和rgba()来设置。opacity属性用于设置元素的不透明级别,rgba()用于对颜色值设置透明度。

    opacity属性

    opacity属性用于设置元素的不透明级别;不透明度的值介于0.0到1.0之间,其中低值表示高透明度,高值表示低透明度。不透明度百分比计算为Opacity%=Opacity* 100。

    语法:

    opacity: value|inherit;

    属性值:

    • value:指定不透明度。从0.0(完全透明)到1.0(完全不透明)

    • inherit:Opacity属性的值应该从父元素继承

    rgba()

    RGBA 的意思是(Red-Green-Blue-Alpha)它是在 RGB 上扩展包括了 “alpha” 通道,运行对颜色值设置透明度。

    语法:

    rgba(R,G,B,A);

    rgba() 里的值的介绍:

    • R:红色值。正整数 (0~255)

    • G:绿色值。正整数 (0~255)

    • B:蓝色值。正整数(0~255)

    • A:透明度。取值0~1之间

    示例1:设置文本透明

    <!DOCTYPE html>  
    <html>  
        <head>  
        	<meta charset="UTF-8">
            <title>Opacity属性</title>  
            <style>  
                .demo {  
                    background: #009991;  
                    padding: 15px;  
                    text-align:center;  
                    300px;  
                }  
          
                #rgba {  
                    padding: 15px;  
                    text-align:center;  
                    300px;  
                }  
                .rgba1 {  
                    background: rgba(0, 153, 145, 0.1);  
                }  
                  
                .rgba2 {  
                    background: rgba(0, 153, 145, 0.5);  
                }  
                  
                .rgba3 {  
                    background: rgba(0, 153, 145, 0.8);  
                }  
                .rgba4 {  
                    background: rgba(0, 153, 145, 1.0);  
                }  
                .g1 {  
                    float:left;  
                    margin-left:50px;  
                }  
                .g2 {  
                    margin-top:-40px;  
                    margin-left:50px;  
                    float:left;  
                }  
            </style>  
        </head>  
        <body>  
            <div class ="g1">  
                <p style = "font-size:24px;font-weight:bold;">透明盒子</p>  
                <div class = "demo"><p>10% 不透明度</p></div>  
                <div class = "demo"><p>50% 不透明度</p></div>  
                <div class = "demo"><p>80% 不透明度</p></div>  
                <div class = "demo"><p>100% 不透明度</p></div></div><br><br>  
                  
            <div class = "g2">  
                <p style = "font-size:24px;font-weight:bold;">rgba颜色值</p>  
                <div id = "rgba"><p>10% 不透明度</p></div>  
                <div id = "rgba"><p>50% 不透明度</p></div>  
                <div id = "rgba"><p>80% 不透明度</p></div>  
                <div id = "rgba"><p>100% 不透明度</p></div> 
            </div>  
        </body>  
    </html>

    效果图:

    示例2:设置图像透明

    <!DOCTYPE html>  
    <html>  
        <head>  
            <title>Opacity属性</title>  
            <style> 
                .forest {
                	 350px;
                    opacity: 0.5;  
                }  
                .opacity {  
                    padding-top:100px; 
                    text-align:center;  
                }  
                body { 
                    background:url(1.jpg) no-repeat; 
                    background-size:cover; 
                } 
            </style>  
        </head>  
        <body>  
            <div class = "opacity"> 
                <img class = "forest" src = "1.jpg">  
            </div>  
        </body>  
    </html>

    效果图:

  • 相关阅读:
    User Get 'Access Denied' with Excel Service WebPart
    How To Search and Restore files from Site Collection Recycle Bin
    How To Collect ULS Log from SharePoint Farm
    How To Restart timer service on all servers in farm
    How to Operate SharePoint User Alerts with PowerShell
    How to get Timer Job History
    Synchronization Service Manager
    SharePoint 2007 Full Text Searching PowerShell and CS file content with SharePoint Search
    0x80040E14 Caused by Max Url Length bug
    SharePoint 2007 User Re-created in AD with new SID issue on MySite
  • 原文地址:https://www.cnblogs.com/ypppt/p/12882837.html
Copyright © 2011-2022 走看看