คุณสมบัติ object-fit ใน CSS ใช้ปรับขนาดรูปภาพหรือวิดีโอให้พอดีกับ container ค่าที่มีดังนี้:
- contain: ขยาย/ย่อเพื่อให้พอดีทั้งหมด
- cover: ครอบคลุม container ทั้งหมด (อาจถูกตัด)
- fill: ยืดเต็ม content box (อาจบิดเบี้ยว)
ตัวอย่าง: ใช้ cover
<!DOCTYPE html> <html> <head> <style> .myimg { width:250px; height:350px; object-fit:fill; } </style> </head> <body> <h2>SWIFT</h2> <img class = "myimg" src = "https://www.tutorialspoint.com/assets/videos/courses/67/images/course_67_image.png" alt = "Python Data Science" width = "300" height = "200"> </body> </html>