-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_position_table.html
More file actions
77 lines (73 loc) · 3.23 KB
/
all_position_table.html
File metadata and controls
77 lines (73 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Positioning Guide</title>
<!-- Link to Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h2 class="mb-4">CSS Positioning Guide</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Position</th>
<th>Meaning</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>static</td>
<td>Default positioning (normal document flow)</td>
<td><code>div { position: static; }</code></td>
</tr>
<tr>
<td>relative</td>
<td>Positions relative to its original location</td>
<td><code>div { position: relative; top: 20px; }</code></td>
</tr>
<tr>
<td>fixed</td>
<td>Positions relative to the viewport (stays in place)</td>
<td><code>header { position: fixed; top: 0; }</code></td>
</tr>
<tr>
<td>absolute</td>
<td>Positions relative to its nearest positioned ancestor</td>
<td><code>.box { position: absolute; top: 50px; left: 100px; }</code></td>
</tr>
<tr>
<td>sticky</td>
<td>Toggle between relative and fixed based on scroll</td>
<td><code>header { position: sticky; top: 0; }</code></td>
</tr>
<tr>
<td>inherit</td>
<td>Inherits position from its parent element</td>
<td><code>.child { position: inherit; }</code></td>
</tr>
<tr>
<td>initial</td>
<td>Resets position to default (static)</td>
<td><code>.element { position: initial; }</code></td>
</tr>
</tbody>
</table>
<h4>Conclusion</h4>
<ul>
<li><strong>static</strong> → Default position, follows normal document flow.</li>
<li><strong>relative</strong> → Positioned relative to its normal position.</li>
<li><strong>fixed</strong> → Positioned relative to the viewport, stays in place when scrolling.</li>
<li><strong>absolute</strong> → Positioned relative to its nearest positioned ancestor.</li>
<li><strong>sticky</strong> → Toggle between relative and fixed based on scrolling.</li>
<li><strong>inherit</strong> → Inherits positioning from the parent.</li>
<li><strong>initial</strong> → Resets to default (static).</li>
</ul>
</div>
<!-- Link to Bootstrap 5 JS (Optional for interactivity) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>