Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

การใช้งานคุณสมบัติ background-color ใน CSS


คุณสมบัติ background-color

คุณสมบัติ background-color ใช้กำหนดสีพื้นหลังขององค์ประกอบ

ตัวอย่าง

ลองรันโค้ดต่อไปนี้เพื่อเรียนรู้การทำงานของคุณสมบัติ background-color:

<html>
  <head>
  </head>
  <body>
    <p style="background-color:blue;">
      This text has a blue background color.</p>
  </body>
<html>

รูปแบบสีที่รองรับ:

  • ชื่อสี: red, blue, transparent
  • HEX: #ff0000, #0000ff, #abcdef
  • RGB/RGBA: rgb(255,0,0), rgba(255,0,0,0.5)
  • HSL/HSLA: hsl(0,100%,50%), hsla(0,100%,50%,0.5)

หมายเหตุ: โครงสร้าง HTML ในตัวอย่างผิดปกติ (body ใน head) ควรแก้ไขให้ถูกต้อง