สไตล์พื้นหลังคุณสมบัติ สี
ตัวอย่าง
ตั้งค่าสีพื้นหลังสำหรับเอกสาร:
document.body.style.backgroundColor = "red";
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
คุณสมบัติ backgroundColor ตั้งค่าหรือคืนค่าสีพื้นหลังขององค์ประกอบ
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
Property | |||||
---|---|---|---|---|---|
backgroundColor | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
ไวยากรณ์
ส่งคืนคุณสมบัติ backgroundColor:
object.style.backgroundColor
ตั้งค่าคุณสมบัติ backgroundColor:
object.style.backgroundColor = "color|transparent|initial|inherit"
มูลค่าทรัพย์สิน
Value | Description |
---|---|
color | Specifies the background color. Look at CSS Color Values for a complete list of possible color values |
transparent | Default. The background color is transparent (underlying content will shine through) |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
รายละเอียดทางเทคนิค
ค่าเริ่มต้น: | โปร่งใส |
---|---|
คืนมูลค่า: | สตริงที่แสดงสีพื้นหลัง |
เวอร์ชัน CSS | CSS1 |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
กำหนดสีพื้นหลังของ <div> องค์ประกอบเฉพาะ:
document.getElementById("myDiv").style.backgroundColor = "lightblue";
ตัวอย่าง
คืนค่าสีพื้นหลังของ <div> องค์ประกอบเฉพาะ:
alert(document.getElementById("myDiv").style.backgroundColor);
ตัวอย่าง
คืนค่าสีพื้นหลังของเอกสาร:
alert(document.body.style.backgroundColor);
หน้าที่เกี่ยวข้อง
กวดวิชาCSS: พื้นหลัง CSS
การอ้างอิง CSS: คุณสมบัติสีพื้นหลัง
การอ้างอิง HTML DOM: คุณสมบัติพื้นหลัง