Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

ปรับขนาด <img> หรือ <video> ให้พอดี Container ด้วย CSS

ใช้คุณสมบัติ object-fit ใน CSS เพื่อปรับขนาดรูปภาพหรือวิดีโอให้พอดีกับ container

ตัวอย่าง

<!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>