اختصار خلفية CSS
خلفية CSS - خاصية الاختزال
لتقصير الكود ، من الممكن أيضًا تحديد جميع خصائص الخلفية في خاصية واحدة. وهذا ما يسمى خاصية الاختزال.
بدلا من الكتابة:
body {
background-color: #ffffff;
background-image:
url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
يمكنك استخدام خاصية الاختزال background
:
مثال
استخدم خاصية الاختزال لتعيين خصائص الخلفية في إعلان واحد:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
عند استخدام خاصية الاختزال ، يكون ترتيب قيم الخاصية كما يلي:
background-color
background-image
background-repeat
background-attachment
background-position
لا يهم ما إذا كانت إحدى قيم الخاصية مفقودة ، طالما أن القيم الأخرى بهذا الترتيب. لاحظ أننا لا نستخدم خاصية background-attachment في الأمثلة أعلاه ، لأنها لا تحتوي على قيمة.
كافة خصائص خلفية CSS
Property | Description |
---|---|
background | Sets all the background properties in one declaration |
background-attachment | Sets whether a background image is fixed or scrolls with the rest of the page |
background-clip | Specifies the painting area of the background |
background-color | Sets the background color of an element |
background-image | Sets the background image for an element |
background-origin | Specifies where the background image(s) is/are positioned |
background-position | Sets the starting position of a background image |
background-repeat | Sets how a background image will be repeated |
background-size | Specifies the size of the background image(s) |