คุณสมบัติ background-attachment
คุณสมบัติ background-attachment ใช้ควบคุมการเลื่อนของภาพในพื้นหลัง
ตัวอย่าง
ลองรันโค้ดต่อไปนี้เพื่อเรียนรู้การทำงานของคุณสมบัติ background-attachment:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url('/css/images/css.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
}
</style>
</head>
<body>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
</body>
</html>
ค่าที่ใช้ได้:
- fixed - ภาพคงที่ ไม่เลื่อนตาม scroll
- scroll - ภาพเลื่อนพร้อมหน้าเว็บ (ค่าเริ่มต้น)
- local - ภาพเลื่อนพร้อมเนื้อหาในองค์ประกอบ