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

ใช้ CSS max-width ทำ Responsive Video Player

ใช้ max-width: 100% และ height: auto ทำให้ Video Player Responsive ไม่เกินขนาดต้นฉบับ

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        video {
            max-width: 100%;
            height: auto;
        }
    </style>
</head>
<body>
    <video width="300" controls autoplay>
        <source src="/html5/foo.ogg" type="video/ogg" />
        <source src="/html5/foo.mp4" type="video/mp4" />
    </video>
    <p>To check the effect, you need to resize the browser.</p>
</body>
</html>

ข้อดีเหนือ width: 100%: Video จะไม่ขยายใหญ่กว่าต้นฉบับ (ไม่เบลอ) แต่จะย่อได้เมื่อ Container เล็กกว่า