สไตล์สีคุณสมบัติ
ตัวอย่าง
ตั้งค่าสีข้อความสำหรับองค์ประกอบต่างๆ:
document.getElementById("myH2").style.color = "#ff0000";
document.getElementById("myP").style.color = "magenta";
document.getElementById("myP2").style.color = "blue";
document.getElementById("myDiv").style.color = "lightblue";
ความหมายและการใช้งาน
คุณสมบัติ color ตั้งค่าหรือคืนค่าสีของข้อความ
รองรับเบราว์เซอร์
Property | |||||
---|---|---|---|---|---|
color | Yes | Yes | Yes | Yes | Yes |
ไวยากรณ์
คืนคุณสมบัติสี:
object.style.color
ตั้งค่าคุณสมบัติสี:
object.style.color = "color|initial|inherit"
มูลค่าทรัพย์สิน
Value | Description |
---|---|
color | Specifies the color of the text. Look at CSS Color Values for a complete list of possible color values |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
รายละเอียดทางเทคนิค
ค่าเริ่มต้น: | ไม่ระบุ |
---|---|
คืนมูลค่า: | สตริง แทนสีข้อความขององค์ประกอบ |
เวอร์ชัน CSS | CSS1 |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
กลับ text-color ของ <p> องค์ประกอบ:
alert(document.getElementById("myP").style.color);
หน้าที่เกี่ยวข้อง
กวดวิชา CSS: CSS Text
การอ้างอิง CSS: คุณสมบัติสี
❮ สไตล์วัตถุ