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

CSS position: absolute


ตำแหน่งสัมพัทธ์กับพาเรนต์ที่มี position

position: absolute นำองค์ประกอบออกจาก normal flow และจัดตำแหน่งเทียบกับ ancestor ใกล้ที่สุดที่มี position ไม่ใช่ static

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
  <style>
    div.one {
      position: relative;
      width: 500px;
      height: 150px;
      border: 2px solid blue;
    }
    div.two {
      position: absolute;
      top: 70px;
      right: 0;
      width: 300px;
      height: 50px;
      border: 2px solid yellow;
    }
  </style>
</head>
<body>
  <h2>position: absolute;</h2>
  <div class="one">div has position: relative;
    <div class="two">div has position: absolute;</div>
  </div>
</body>
</html>