خاصية تناسب الكائن في CSS
مثال
قم بقص جوانب الصورة ، مع الاحتفاظ بنسبة العرض إلى الارتفاع ، واملأ الفراغ:
img.a {
width: 200px;
height:
400px;
object-fit: cover;
}
التعريف والاستخدام
تُستخدم object-fit
الخاصية لتحديد كيفية تغيير حجم <img> أو <video> ليناسب الحاوية الخاصة به.
تخبر هذه الخاصية المحتوى بملء الحاوية بعدة طرق ؛ مثل "الحفاظ على نسبة العرض إلى الارتفاع" أو "التمدد وشغل أكبر مساحة ممكنة".
القيمة الافتراضية: | انظر الخصائص الفردية |
---|---|
وارث: | رقم |
متحرك: | رقم. اقرأ عن animatable |
الإصدار: | CSS3 |
بناء جملة JavaScript: | الكائن .style.objectFit = "الغلاف" |
دعم المتصفح
تحدد الأرقام الواردة في الجدول إصدار المتصفح الأول الذي يدعم الخاصية بالكامل.
Property | |||||
---|---|---|---|---|---|
object-fit | 31.0 | 16.0 | 36.0 | 7.1 | 19.0 |
بنية CSS
object-fit: fill|contain|cover|scale-down|none|initial|inherit;
قيم الملكية
Value | Description | Try it |
---|---|---|
fill | This is default. The replaced content is sized to fill the element's content box. If necessary, the object will be stretched or squished to fit | |
contain | The replaced content is scaled to maintain its aspect ratio while fitting within the element's content box | |
cover | The replaced content is sized to maintain its aspect ratio while filling the element's entire content box. The object will be clipped to fit | |
none | The replaced content is not resized | |
scale-down | The content is sized as if none or contain were specified (would result in a smaller concrete object size) | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
الصفحات ذات الصلة
برنامج CSS التعليمي: CSS object-fit
مرجع CSS: موضع كائن CSS
مرجع HTML DOM: خاصية objectFit