خاصية لون الخلفية في CSS
مثال
عيّن لون الخلفية للصفحة:
body {background-color: coral;}
المزيد من الأمثلة "جربها بنفسك" أدناه.
التعريف والاستخدام
تحدد الخاصية لون background-color
خلفية العنصر.
خلفية العنصر هي الحجم الإجمالي للعنصر ، بما في ذلك المساحة المتروكة والحد (ولكن ليس الهامش).
نصيحة: استخدم لون الخلفية ولون النص الذي يسهل قراءة النص.
القيمة الافتراضية: | شفاف |
---|---|
وارث: | رقم |
متحرك: | نعم. اقرأ عن animatable |
الإصدار: | 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
مرجع DOM HTML: خاصية backgroundColor