خاصية وضع الخلفية في CSS
مثال
كيفية وضع صورة الخلفية:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
المزيد من الأمثلة "جربها بنفسك" أدناه.
التعريف والاستخدام
background-position
تحدد الخاصية موضع البداية لصورة الخلفية .
نصيحة: بشكل افتراضي ، يتم وضع صورة الخلفية في الزاوية العلوية اليسرى من العنصر ، ويتم تكرارها عموديًا وأفقيًا.
القيمة الافتراضية: | 0٪ 0٪ |
---|---|
وارث: | رقم |
متحرك: | نعم. اقرأ عن animatable |
الإصدار: | CSS1 |
بناء جملة JavaScript: | الكائن .style.backgroundPosition = "المركز" |
دعم المتصفح
تحدد الأرقام الواردة في الجدول إصدار المتصفح الأول الذي يدعم الخاصية بالكامل.
Property | |||||
---|---|---|---|---|---|
background-position | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
ملاحظة: IE8 والإصدارات الأقدم لا تدعم صور خلفية متعددة على عنصر واحد.
بنية CSS
background-position: value;
قيم الملكية
Value | Description | Play it |
---|---|---|
left top left center left bottom right top right center right bottom center top center center center bottom |
If you only specify one keyword, the other value will be "center" | |
x% y% | The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. Default value is: 0% 0% | |
xpos ypos | The first value is the horizontal position and the second value is the vertical. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and positions | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
مزيد من الأمثلة
مثال
كيفية وضع صورة الخلفية لتكون في المنتصف في الأعلى:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center top;
}
مثال
كيفية وضع صورة الخلفية في أسفل اليمين:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: bottom right;
}
مثال
كيفية وضع صورة الخلفية باستخدام النسبة المئوية:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 50% 50%;
}
مثال
كيفية وضع صورة الخلفية باستخدام البكسل:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 50px 150px;
}
مثال
استخدم خصائص خلفية مختلفة لإنشاء صورة "رئيسية":
.hero-image {
background-image: url("photographer.jpg"); /* The
image used */
background-color: #cccccc; /* Used if the image is
unavailable */
height: 500px; /* You must set a specified height */
background-position: center; /* Center the image */
background-repeat: no-repeat; /* Do not repeat the image */
background-size: cover; /* Resize the background image to cover the entire container */
}
الصفحات ذات الصلة
دروس CSS: خلفية CSS
مرجع CSS: خاصية صورة الخلفية
مرجع DOM HTML: خاصية backgroundPosition