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

CSS position: fixed


ตำแหน่งคงที่เทียบกับ viewport

position: fixed ทำให้องค์ประกอบอยู่ตำแหน่งเดิมบนหน้าจอแม้จะเลื่อนสกรอลล์ ใช้ top, right, bottom, left กำหนดตำแหน่ง

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
  <style>
    div {
      position: fixed;
      bottom: 0;
      right: 0;
      width: 200px;
      border: 3px solid blue;
    }
  </style>
</head>
<body>
  <h2>position: fixed;</h2>
  <p>ตำแหน่งคงที่เทียบกับ viewport</p>
  <div>div has position: fixed;</div>
</body>
</html>