ในการตั้งค่าการแนบพื้นหลัง ให้ใช้คุณสมบัติการแนบพื้นหลัง ไฟล์แนบพื้นหลังกำหนดว่าภาพพื้นหลังได้รับการแก้ไขหรือเลื่อนพร้อมกับส่วนที่เหลือของหน้า
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อเรียนรู้วิธีทำงานกับคุณสมบัติ 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>
<p>The background-image is fixed. Try to scroll down the page.</p>
</body>
</html>