نمط objectFit خاصية
مثال
قم بقص جوانب الصورة ، مع الاحتفاظ بنسبة العرض إلى الارتفاع ، واملأ الفراغ:
document.getElementById("myImg").style.objectFit = "cover";
التعريف والاستخدام
تُستخدم الخاصية objectFit لتحديد كيفية تغيير حجم <img> أو <video> ليلائم الحاوية الخاصة به.
تخبر هذه الخاصية المحتوى بملء الحاوية بعدة طرق ؛ مثل "الحفاظ على نسبة العرض إلى الارتفاع" أو "التمدد وشغل أكبر مساحة ممكنة"
دعم المتصفح
تحدد الأرقام الواردة في الجدول إصدار المتصفح الأول الذي يدعم الخاصية بالكامل.
Property | |||||
---|---|---|---|---|---|
objectFit | 31.0 | 16.0 | 36.0 | 7.1 | 19.0 |
بناء الجملة
إرجاع خاصية objectFit:
object.style.objectFit
قم بتعيين خاصية objectFit:
object.style.objectFit = "fill|contain|cover|scale-down|none|initial|inherit"
قيم الملكية
Value | Description |
---|---|
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 | CSS3 |
الصفحات ذات الصلة
برنامج CSS التعليمي: CSS object-fit
مرجع CSS: خاصية تناسب الكائن
❮ نمط الكائن