使用 RGBA 的 CSS 透明度
使用 RGBA() 值表示 CSS 透明度。設定 alpha 通道引數可指定顏色的不透明度 −
.transparent { background-color: rgba(0, 0, 255, 0.582); }
RGBA 顏色值包括 rgba(紅色,綠色,藍色,alpha)。此處,將 alpha 設定為透明度,即 −
0.0:完全透明
1.0:完全不透明
使用 RGBA 實現透明度
以下為使用 RGBA 實現 CSS 透明度的程式碼。此處,我們將 alpha 引數設定為 0.582 以表示透明度 −
示例
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } div { width: 200px; height: 200px; background-color: rgb(0, 0, 255); color: white; display: inline-block; } .transparent { background-color: rgba(0, 0, 255, 0.582); } </style> </head> <body> <h1>Transparency using RGBA example</h1> <div class="transparent"> This is a demo text. </div> <div> This is another demo text. </div> </body> </html>
使用 RGBA 實現完全透明
以下為使用 RGBA 實現 CSS 透明度的程式碼。此處,我們將 alpha 引數設定為 0.0 以表示完全透明 −
示例
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } div { width: 200px; height: 200px; background-color: rgb(0, 0, 255); color: white; display: inline-block; } .transparent { background-color: rgba(0, 0, 255, 0.0); } </style> </head> <body> <h1>Transparency using RGBA example</h1> <div class="transparent"> This is a demo text. </div> <div> This is another demo text. </div> </body> </html>
使用 RGBA 實現完全不透明
以下為使用 RGBA 實現 CSS 透明度的程式碼。此處,我們將 alpha 引數設定為 1.0 以表示完全不透明 −
示例
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } div { width: 200px; height: 200px; background-color: rgb(0, 0, 255); color: white; display: inline-block; } .transparent { background-color: rgba(0, 0, 255, 1.0); } </style> </head> <body> <h1>Transparency using RGBA example</h1> <div class="transparent"> This is a demo text. </div> <div> This is another demo text. </div> </body> </html>
廣告