CSS rgb()ฟังก์ชั่น
ตัวอย่าง
กำหนดสี RGB ที่แตกต่างกัน:
#p1 {background-color:rgb(255,0,0);} /* red */
#p2 {background-color:rgb(0,255,0);} /* green */
#p3 {background-color:rgb(0,0,255);} /* blue */
ความหมายและการใช้งาน
ฟังก์ชัน rgb() กำหนดสีโดยใช้โมเดลสีแดง-เขียว-น้ำเงิน (RGB)
ค่าสี RGB ระบุด้วย: rgb(แดง เขียว น้ำเงิน) พารามิเตอร์แต่ละตัวกำหนดความเข้มของสีนั้น และสามารถเป็นจำนวนเต็มระหว่าง 0 ถึง 255 หรือค่าเปอร์เซ็นต์ (จาก 0% ถึง 100%)
ตัวอย่างเช่น ค่า rgb(0,0,255) จะแสดงเป็นสีน้ำเงิน เนื่องจากพารามิเตอร์สีน้ำเงินถูกตั้งค่าเป็นค่าสูงสุด (255) และค่าอื่นๆ ถูกกำหนดเป็น 0
รุ่น: | CSS2 |
---|
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่รองรับฟังก์ชันนี้อย่างเต็มที่
Function | |||||
---|---|---|---|---|---|
rgb() | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
ไวยากรณ์ CSS
rgb(red, green, blue)
Value | Description |
---|---|
red | Defines the intensity of red as an integer between 0 and 255, or as a percentage value between 0% and 100% |
green | Defines the intensity of green as an integer between 0 and 255, or as a percentage value between 0% and 100% |
blue | Defines the intensity of blue as an integer between 0 and 255, or as a percentage value between 0% and 100% |