สำหรับองค์ประกอบการจัดตำแหน่ง CSS มีวิธีการกำหนดตำแหน่งดังต่อไปนี้ -
การวางตำแหน่งสัมพัทธ์ใน CSS
ด้วยการวางตำแหน่งสัมพัทธ์ องค์ประกอบจะอยู่ในตำแหน่งที่สัมพันธ์กับตำแหน่งปกติ สำหรับสิ่งนี้ ให้ใช้ตำแหน่ง:สัมพันธ์
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
div.demo {
position: relative;
color: white;
background-color: orange;
border: 2px dashed blue;
left: 50px;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<p>This is demo text.</p>
<p>This is demo text.</p>
<div class="demo">
position: relative;
</div>
<p>This is another demo text.</p>
</body>
</html> ผลลัพธ์

การวางตำแหน่งสัมบูรณ์ใน CSS
ด้วยการวางตำแหน่งแบบสัมบูรณ์ องค์ประกอบจะอยู่ในตำแหน่งที่สัมพันธ์กับตำแหน่งบรรพบุรุษที่ใกล้ที่สุด
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
div.demo1 {
position: relative;
color: white;
background-color: orange;
border: 2px dashed blue;
width: 600px;
height: 200px;
}
div.demo2 {
position: absolute;
color: white;
background-color: orange;
border: 2px dashed blue;
top: 50px;
right: 0;
width: 300px;
height: 100px;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<p>This is demo text.</p>
<p>This is demo text.</p>
<p>This is demo text.</p>
<p>This is demo text.</p>
<div class="demo1">position: relative;
<div class="demo2">
position: absolute;
</div>
</div>
<p>This is another demo text.</p>
<p>This is demo text.</p>
<p>This is demo text.</p>
</body>
</html> ผลลัพธ์

การกำหนดตำแหน่งคงที่ใน CSS
ชุดองค์ประกอบที่มีตำแหน่ง:คงที่; ยังคงอยู่ที่เดิมแม้ว่าจะเลื่อนหน้าไปก็ตาม
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
div.demo1 {
position: relative;
color: white;
background-color: orange;
border: 2px dashed blue;
width: 600px;
height: 200px;
}
div.demo2 {
position: absolute;
color: white;
background-color: orange;
border: 2px dashed blue;
top: 50px;
right: 0;
width: 300px;
height: 100px;
}
div.demo3 {
position: fixed;
bottom: 0;
right: 20px;
width: 500px;
border: 3px solid orange;
color: blue;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<p>This is demo text.</p>
<p>This is demo text.</p>
<p>This is demo text.</p>
<p>This is demo text.</p>
<div class="demo1">position: relative;
<div class="demo2">
position: absolute;
</div>
<div class="demo3">
position: fixed;
</div>
</div>
<p>This is another demo text.</p>
</body>
</html> ผลลัพธ์
