
- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 包含
- CSS - 測量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 內聯邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 內聯塊
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - Clearfix
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 順序
- CSS - 位置
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 聚焦
- CSS - 縮放
- CSS - 平移
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 導航欄
- CSS - 疊加層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪裁
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - 全部
- CSS - 內嵌
- CSS - 隔離
- CSS - 溢位滾動
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - 指標事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大塊級尺寸
- CSS - 最小塊級尺寸
- CSS - 混合模式
- CSS - 最大內聯尺寸
- CSS - 最小內聯尺寸
- CSS - 偏移量
- CSS - 強調色
- CSS - 使用者選擇
- CSS 高階
- CSS - 網格
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字特效
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - !important
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多重背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - 盒裝飾中斷
- CSS - 游標顏色
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 樣式圖片
- CSS - 特效性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS 函式 - rgb()
CSS 中的rgb()函式用於使用RGB(紅、綠、藍)顏色模型定義顏色值。它允許您透過指定這三種原色的強度來指定顏色。
要新增顏色透明度,可以將可選的<alpha-value>傳遞給rgb()函式。
傳統函式rgba()是函式rgb()的別名,它們都接受相同的引數並以相同的方式執行。
可能的值
rgb()函式的函式表示法為rgb(R G B[ / A])。
R, G, B:可以包含任何表示紅色、綠色和藍色通道的格式。
<number>:0到255之間的任何數字。
<percentage>:0%到100%之間的任何值。
關鍵字 none
A:表示顏色的透明度。這是一個可選值。
<alpha-value>:0到1之間的任何數字,其中1對應於完全不透明,0對應於完全透明。
關鍵字 none
由於函式表示法將其序列化為sRGB,因此紅色、綠色和藍色分量的值在序列化時會四捨五入。
語法
rgb(255 255 255) | rgb(255, 255, 255) | rgb(255 255 255 /0.5)
CSS rgb() - 數值
以下示例顯示了rgb()函式的使用,其中所有三個值都帶有和不帶有alpha值(數值)。
<html> <head> <style> div { width: 100px; height: 100px; border: 2px solid black; margin-bottom: 10px; } .color-rgb-red{ background-color: rgb(255 0 0); } .color-rgb-green{ background-color: rgb(0 255 0); } .color-rgb-blue{ background-color: rgb(0 0 255); } .color-rgb-alpha{ background-color: rgba(255 0 0 /0.5); } </style> </head> <body> <div class="color-rgb-red">rgb(255 0 0)</div> <div class="color-rgb-green">rgb(0 255 0)</div> <div class="color-rgb-blue">rgb(0 0 255)</div> <div class="color-rgb-alpha">rgba(255 0 0 /0.5)</div> </body> </html>
CSS rgb() - 百分比值
以下示例顯示了rgb()函式的使用,其中所有三個值都帶有和不帶有alpha值(百分比值)。
<html> <head> <style> div { width: 100px; height: 100px; border: 2px solid black; margin-bottom: 10px; } .color-rgb-red { background-color: rgb(70% 30% 10%); } .color-rgb-comma { background-color: rgb(0%, 55%, 20%); } .color-rgb-blue { background-color: rgb(10% 10% 85%); } .color-rgb-alpha-number { background-color: rgba(0% 40% 50% /0.5); } .color-rgb-alpha-percent { background-color: rgba(70% 0% 50% /12%); } </style> </head> <body> <div class="color-rgb-red">rgb(70% 30% 10%)</div> <div class="color-rgb-comma">rgb(comma-separated)</div> <div class="color-rgb-blue">rgb(10% 10% 85%)</div> <div class="color-rgb-alpha-number">rgba(0% 40% 50% /0.5)</div> <div class="color-rgb-alpha-percent">rgba(70% 40% 50% /12%)</div> </body> </html>
廣告