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

ตั้งค่าภาพพื้นหลังคงที่ (fixed) ด้วย CSS


background-attachment: fixed

ใช้ background-attachment: fixed ทำให้ภาพพื้นหลังไม่เลื่อนตามเนื้อหา (parallax effect)

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
  <style>
    body {
      background-image: url("https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg");
      background-repeat: no-repeat;
      background-attachment: fixed;
      background-position: right top;
    }
  </style>
</head>
<body>
  <h1>Background Image</h1>
</body>
</html>