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

จะสร้างภาพที่ตอบสนองด้วย CSS ได้อย่างไร?


ต่อไปนี้คือโค้ดสำหรับสร้างรูปภาพที่ตอบสนองด้วย CSS -

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
img {
   width: 100%;
   max-width: 1000px;
}
</style>
</head>
<body>
<h1>Responsive Images Example</h1>
<h2>Resize the window to see responsive image scale up and down</h2>
<img src="https://images.pexels.com/photos/34950/pexels-photo.jpg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940">
</body>
</html>

ผลลัพธ์

รหัสข้างต้นจะสร้างผลลัพธ์ต่อไปนี้ -

จะสร้างภาพที่ตอบสนองด้วย CSS ได้อย่างไร?

ในการปรับขนาดเบราว์เซอร์ รูปภาพจะย่อขนาดลงดังนี้ −

จะสร้างภาพที่ตอบสนองด้วย CSS ได้อย่างไร?