คุณสมบัติสีพื้นหลัง CSS
ตัวอย่าง
กำหนดสีพื้นหลังสำหรับหน้า:
body {background-color: coral;}
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
คุณสมบัติbackground-color
กำหนดสีพื้นหลังขององค์ประกอบ
พื้นหลังขององค์ประกอบคือขนาดทั้งหมดขององค์ประกอบ รวมถึงการเติมและเส้นขอบ (แต่ไม่ใช่ระยะขอบ)
เคล็ดลับ:ใช้สีพื้นหลังและสีข้อความที่ทำให้อ่านข้อความได้ง่าย
ค่าเริ่มต้น: | โปร่งใส |
---|---|
รับการถ่ายทอด: | ไม่ |
เคลื่อนไหวได้: | ใช่. อ่านเกี่ยวกับแอนิเมชั่น |
รุ่น: | CSS1 |
ไวยากรณ์ JavaScript: | วัตถุ .style.backgroundColor="#00FF00" |
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
Property | |||||
---|---|---|---|---|---|
background-color | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
ไวยากรณ์ CSS
background-color: color|transparent|initial|inherit;
มูลค่าทรัพย์สิน
Value | Description | Play it |
---|---|---|
color | Specifies the background color. Look at CSS Color Values for a complete list of possible color values. | |
transparent | Specifies that the background color should be transparent. This is default | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ระบุสีพื้นหลังด้วยค่า HEX:
body {background-color: #92a8d1;}
ตัวอย่าง
ระบุสีพื้นหลังด้วยค่า RGB:
body {background-color: rgb(201, 76, 76);}
ตัวอย่าง
ระบุสีพื้นหลังด้วยค่า RGBA:
body {background-color: rgba(201, 76, 76, 0.3);}
ตัวอย่าง
ระบุสีพื้นหลังด้วยค่า HSL:
body {background-color: hsl(89, 43%, 51%);}
ตัวอย่าง
ระบุสีพื้นหลังด้วยค่า HSLA:
body {background-color: hsla(89, 43%, 51%, 0.3);}
ตัวอย่าง
ตั้งค่าสีพื้นหลังสำหรับองค์ประกอบต่างๆ:
body {
background-color: #fefbd8;
}
h1 {
background-color: #80ced6;
}
div {
background-color: #d5f4e6;
}
span {
background-color: #f18973;
}
หน้าที่เกี่ยวข้อง
กวดวิชาCSS: พื้นหลัง CSS
การอ้างอิง HTML DOM: คุณสมบัติ backgroundColor