🧱 position: static
Default position for all elements.
Not affected by top, right, bottom, or left properties.
Elements flow naturally in the document (top to bottom).
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Static Position Anatomy</title>
<style>
.infographic-staticpos {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
box-sizing: border-box;
margin: 0 auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
border-radius: 14px;
overflow: hidden;
}
.infographic-staticpos[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
}
.ha-inner { padding: 0.5rem; }
.ha-layout { display: flex; flex-direction: column; gap: 1.5rem; }
.ha-code-wrap {
background: #0b0b0b;
border: 1px solid #2a2a2a;
border-radius: 10px;
overflow: hidden;
}
.ha-filetabs {
display: flex;
background: #161616;
border-bottom: 1px solid #2a2a2a;
}
.ha-filetab {
border: none;
background: transparent;
color: #8a8a8a;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
font-weight: 700;
padding: 0.6rem 1rem;
cursor: pointer;
border-bottom: 2px solid transparent;
transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.ha-filetab:hover { color: #e5e5e5; }
.ha-filetab.ha-tab-on {
color: #ffffff;
border-bottom-color: #5b8def;
background: #0b0b0b;
}
.ha-code {
padding: 1rem 1.8rem 1rem 0.9rem;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
line-height: 1.85;
overflow-x: auto;
}
.ha-codepane { display: none; }
.ha-codepane.ha-pane-on { display: block; }
.ha-line { display: block; white-space: pre; color: #8a8a8a; padding: 0.05rem 0.4rem; border-radius: 5px; }
.ha-tag { color: #60a5fa; font-weight: 700; }
.ha-attr { color: #f2b96b; }
.ha-str { color: #9ece6a; }
.ha-sel { color: #f472b6; font-weight: 700; }
.ha-prop { color: #c586c0; }
.ha-val { color: #ce9178; }
.ha-pos-val { color: #ffd166; font-weight: 800; }
.ha-nofx { color: #6b6b6b; text-decoration: line-through; }
.ha-comment { color: #5c6370; font-style: italic; }
.ha-browser {
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: var(--paper);
}
.ha-browser-bar {
background: var(--paper-alt);
padding: 0.5rem 0.7rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid var(--line);
}
.ha-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.ha-tab {
background: var(--paper);
border: 1px solid var(--line);
border-bottom: none;
border-radius: 6px 6px 0 0;
font-size: 0.72rem;
color: var(--ink-soft);
padding: 0.25rem 0.6rem;
}
.ha-urlrow {
background: var(--paper-alt);
padding: 0.35rem 0.7rem 0.6rem;
font-size: 0.72rem;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
}
.ha-screen {
background: #ffffff;
color: #111;
padding: 1.4rem;
display: flex;
justify-content: center;
}
.ha-out-box {
width: 250px;
box-sizing: border-box;
padding: 20px;
background-color: #ffd700;
position: static;
top: 10px;
margin: 10px auto;
font-family: Arial, sans-serif;
font-size: 0.9rem;
text-align: center;
}
.ha-note {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: 0.78rem;
color: var(--ink-soft);
text-align: center;
margin-top: 0.7rem;
}
</style>
</head>
<body>
<div class="infographic-staticpos" id="ha-root">
<div class="ha-inner">
<div class="ha-layout">
<div class="ha-code-wrap">
<div class="ha-filetabs">
<button class="ha-filetab ha-tab-on" id="tab-html">index.html</button>
<button class="ha-filetab" id="tab-css">style.css</button>
</div>
<div class="ha-code">
<div class="ha-codepane ha-pane-on" id="pane-html">
<span class="ha-line"><<span class="ha-tag">body</span>></span>
<span class="ha-line"> <<span class="ha-tag">div</span> <span class="ha-attr">class</span>=<span class="ha-str">"box"</span>>This box uses static positioning.</<span class="ha-tag">div</span>></span>
<span class="ha-line"></<span class="ha-tag">body</span>></span>
</div>
<div class="ha-codepane" id="pane-css">
<span class="ha-line"><span class="ha-sel">.box</span> {</span>
<span class="ha-line"> <span class="ha-prop">width</span>: <span class="ha-val">250px</span>;</span>
<span class="ha-line"> <span class="ha-prop">padding</span>: <span class="ha-val">20px</span>;</span>
<span class="ha-line"> <span class="ha-prop">background-color</span>: <span class="ha-val">#ffd700</span>;</span>
<span class="ha-line"> <span class="ha-prop">position</span>: <span class="ha-pos-val">static</span>;</span>
<span class="ha-line"> <span class="ha-nofx">top: 10px;</span> <span class="ha-comment">/* no effect on static */</span></span>
<span class="ha-line"> <span class="ha-prop">margin</span>: <span class="ha-val">40px auto</span>;</span>
<span class="ha-line">}</span>
</div>
</div>
</div>
<div class="ha-browser">
<div class="ha-browser-bar">
<span class="ha-dot"></span><span class="ha-dot"></span><span class="ha-dot"></span>
<div class="ha-tab">🌐 Static Position Example</div>
</div>
<div class="ha-urlrow">127.0.0.1:5500/basicstructure.html</div>
<div class="ha-screen">
<div>
<div class="ha-out-box">This box uses static positioning.</div>
<div class="ha-note"><code>position: static</code> is the default — <code>top</code>, <code>left</code>, <code>right</code>, and <code>bottom</code> are all ignored. Only margin controls where this box sits.</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('ha-root');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
(function () {
const tabHtml = document.getElementById('tab-html');
const tabCss = document.getElementById('tab-css');
const paneHtml = document.getElementById('pane-html');
const paneCss = document.getElementById('pane-css');
tabHtml.addEventListener('click', () => {
tabHtml.classList.add('ha-tab-on');
tabCss.classList.remove('ha-tab-on');
paneHtml.classList.add('ha-pane-on');
paneCss.classList.remove('ha-pane-on');
});
tabCss.addEventListener('click', () => {
tabCss.classList.add('ha-tab-on');
tabHtml.classList.remove('ha-tab-on');
paneCss.classList.add('ha-pane-on');
paneHtml.classList.remove('ha-pane-on');
});
})();
</script>
</body>
</html>.demo {
font-family: system-ui, sans-serif;
padding: 16px;
}
.demo h1 {
color: #2563eb;
margin: 0 0 8px;
}
.demo p {
color: #4b5563;
margin: 0;
}document.querySelector('.demo h1')?.addEventListener('click', () => {
alert('Hello from live preview!');
});🎯 position: relative
Positions the element relative to its normal position.
Can be moved using top, right, bottom, or left.
Still takes up space in the layout (like it never moved).
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Relative Position Anatomy</title>
<style>
.infographic-relativepos {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
box-sizing: border-box;
margin: 0 auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
border-radius: 14px;
overflow: hidden;
}
.infographic-relativepos[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
}
.ha-inner { padding: 0.5rem; }
.ha-layout { display: flex; flex-direction: column; gap: 1.2rem; }
.ha-code-wrap {
background: #0b0b0b;
border: 1px solid #2a2a2a;
border-radius: 10px;
overflow: hidden;
}
.ha-filetabs {
display: flex;
background: #161616;
border-bottom: 1px solid #2a2a2a;
}
.ha-filetab {
border: none;
background: transparent;
color: #8a8a8a;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
font-weight: 700;
padding: 0.6rem 1rem;
cursor: pointer;
border-bottom: 2px solid transparent;
transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.ha-filetab:hover { color: #e5e5e5; }
.ha-filetab.ha-tab-on {
color: #ffffff;
border-bottom-color: #5b8def;
background: #0b0b0b;
}
.ha-code {
padding: 1rem 1.8rem 1rem 0.9rem;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
line-height: 1.85;
overflow-x: auto;
}
.ha-codepane { display: none; }
.ha-codepane.ha-pane-on { display: block; }
.ha-line { display: block; white-space: pre; color: #8a8a8a; padding: 0.05rem 0.4rem; }
.ha-tag { color: #60a5fa; font-weight: 700; }
.ha-attr { color: #f2b96b; }
.ha-str { color: #9ece6a; }
.ha-sel { color: #f472b6; font-weight: 700; }
.ha-prop { color: #c586c0; }
.ha-val { color: #ce9178; }
.ha-pos-val { color: #ffd166; font-weight: 800; }
.ha-extra-line { display: none; }
.ha-extra-line.ha-show { display: block; }
.ha-toggle {
display: flex;
background: var(--paper-alt);
border: 1px solid var(--line);
border-radius: 999px;
padding: 0.25rem;
gap: 0.25rem;
}
.ha-toggle button {
flex: 1;
border: none;
background: transparent;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 0.8rem;
font-weight: 700;
padding: 0.55rem 0.8rem;
border-radius: 999px;
cursor: pointer;
transition: background 0.2s ease, color 0.2s ease;
}
.ha-toggle button.ha-on { background: var(--accent); color: #fff; }
.ha-browser {
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: var(--paper);
}
.ha-browser-bar {
background: var(--paper-alt);
padding: 0.5rem 0.7rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid var(--line);
}
.ha-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.ha-tab {
background: var(--paper);
border: 1px solid var(--line);
border-bottom: none;
border-radius: 6px 6px 0 0;
font-size: 0.72rem;
color: var(--ink-soft);
padding: 0.25rem 0.6rem;
}
.ha-urlrow {
background: var(--paper-alt);
padding: 0.35rem 0.7rem 0.6rem;
font-size: 0.72rem;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
}
.ha-screen {
background: #ffffff;
color: #111;
padding: 1.2rem 1.4rem 1.6rem;
font-family: Georgia, "Times New Roman", serif;
min-height: 260px;
position: relative;
}
.ha-out-box {
width: 120px;
height: 120px;
margin: 15px;
background-color: skyblue;
font-size: 0.85rem;
padding: 0.2rem 0.3rem;
box-sizing: border-box;
position: relative;
top: 0;
left: 0;
transition: top 0.4s ease, left 0.4s ease;
}
.ha-out-box.ha-shifted {
top: 24px;
left: 80px;
}
.ha-out-p {
font-size: 0.88rem;
margin: 0.4rem 0 0;
}
.ha-note {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: 0.78rem;
color: var(--ink-soft);
}
</style>
</head>
<body>
<div class="infographic-relativepos" id="ha-root">
<div class="ha-inner">
<div class="ha-layout">
<div class="ha-code-wrap">
<div class="ha-filetabs">
<button class="ha-filetab ha-tab-on" id="tab-html">index.html</button>
<button class="ha-filetab" id="tab-css">style.css</button>
</div>
<div class="ha-code">
<div class="ha-codepane ha-pane-on" id="pane-html">
<span class="ha-line"><<span class="ha-tag">body</span>></span>
<span class="ha-line"> <<span class="ha-tag">div</span> <span class="ha-attr">class</span>=<span class="ha-str">"container"</span>></span>
<span class="ha-line"> <<span class="ha-tag">div</span> <span class="ha-attr">class</span>=<span class="ha-str">"box"</span>>I am relative</<span class="ha-tag">div</span>></span>
<span class="ha-line"> <<span class="ha-tag">p</span>>I appear after the box.</<span class="ha-tag">p></span></span>
<span class="ha-line"> </<span class="ha-tag">div</span>></span>
<span class="ha-line"></<span class="ha-tag">body</span>></span>
</div>
<div class="ha-codepane" id="pane-css">
<span class="ha-line"><span class="ha-sel">.box</span> {</span>
<span class="ha-line"> <span class="ha-prop">width</span>: <span class="ha-val">150px</span>;</span>
<span class="ha-line"> <span class="ha-prop">height</span>: <span class="ha-val">150px</span>;</span>
<span class="ha-line"> <span class="ha-prop">margin</span>: <span class="ha-val">20px</span>;</span>
<span class="ha-line"> <span class="ha-prop">background-color</span>: <span class="ha-val">skyblue</span>;</span>
<span class="ha-line ha-extra-line" id="line-pos"> <span class="ha-prop">position</span>: <span class="ha-pos-val">relative</span>;</span>
<span class="ha-line ha-extra-line" id="line-top"> <span class="ha-prop">top</span>: <span class="ha-val">30px</span>;</span>
<span class="ha-line ha-extra-line" id="line-left"> <span class="ha-prop">left</span>: <span class="ha-val">100px</span>;</span>
<span class="ha-line">}</span>
</div>
</div>
</div>
<div class="ha-toggle">
<button class="ha-on" id="btn-before">Before</button>
<button id="btn-after">After position: relative</button>
</div>
<div class="ha-browser">
<div class="ha-browser-bar">
<span class="ha-dot"></span><span class="ha-dot"></span><span class="ha-dot"></span>
<div class="ha-tab">🌐 127.0.0.1:5500/html</div>
</div>
<div class="ha-urlrow">127.0.0.1:5500/html</div>
<div class="ha-screen">
<div class="ha-out-box" id="out-box">I am relative</div>
<p class="ha-out-p">I appear after the box.</p>
</div>
</div>
<div class="ha-note" id="note-out">The box sits in its normal spot — no offset applied yet.</div>
</div>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('ha-root');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
(function () {
const tabHtml = document.getElementById('tab-html');
const tabCss = document.getElementById('tab-css');
const paneHtml = document.getElementById('pane-html');
const paneCss = document.getElementById('pane-css');
tabHtml.addEventListener('click', () => {
tabHtml.classList.add('ha-tab-on');
tabCss.classList.remove('ha-tab-on');
paneHtml.classList.add('ha-pane-on');
paneCss.classList.remove('ha-pane-on');
});
tabCss.addEventListener('click', () => {
tabCss.classList.add('ha-tab-on');
tabHtml.classList.remove('ha-tab-on');
paneCss.classList.add('ha-pane-on');
paneHtml.classList.remove('ha-pane-on');
});
const btnBefore = document.getElementById('btn-before');
const btnAfter = document.getElementById('btn-after');
const box = document.getElementById('out-box');
const note = document.getElementById('note-out');
const extraLines = [document.getElementById('line-pos'), document.getElementById('line-top'), document.getElementById('line-left')];
btnBefore.addEventListener('click', () => {
btnBefore.classList.add('ha-on');
btnAfter.classList.remove('ha-on');
box.classList.remove('ha-shifted');
extraLines.forEach(l => l.classList.remove('ha-show'));
note.textContent = 'The box sits in its normal spot — no offset applied yet.';
});
btnAfter.addEventListener('click', () => {
btnAfter.classList.add('ha-on');
btnBefore.classList.remove('ha-on');
box.classList.add('ha-shifted');
extraLines.forEach(l => l.classList.add('ha-show'));
note.textContent = 'The box visually shifts 30px down and 100px right from where it would normally sit — but its original space is still reserved, which is why it can end up overlapping the paragraph below.';
});
})();
</script>
</body>
</html>.demo {
font-family: system-ui, sans-serif;
padding: 16px;
}
.demo h1 {
color: #2563eb;
margin: 0 0 8px;
}
.demo p {
color: #4b5563;
margin: 0;
}document.querySelector('.demo h1')?.addEventListener('click', () => {
alert('Hello from live preview!');
});📌 position: absolute
When you apply position: absolute to an element:
It is removed from the normal document flow, meaning it does not take up space anymore.
It is positioned based on its nearest positioned ancestor — the nearest parent with a
positionofrelative,absolute, orfixedIf no such ancestor exists, the element is positioned relative to the
<html>(the entire page or viewport).
<aside>
Think of position: absolute like saying: “Take me out of the regular layout and let me float at these exact coordinates — but only within the box of my nearest positioned ancestor.”
</aside>
🔸 Common Mistake:
Many people apply position: absolute and get unexpected results because they forget to set position: relative on the parent container.
✅ Example : Absolute Without a Positioned Ancestor and with position: Relative
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Absolute Position Anatomy</title>
<style>
.infographic-absolutepos {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
box-sizing: border-box;
margin: 0 auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
border-radius: 14px;
overflow: hidden;
}
.infographic-absolutepos[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
}
.ha-inner { padding: 0.5rem; }
.ha-layout { display: flex; flex-direction: column; gap: 1.2rem; }
.ha-code-wrap {
background: #0b0b0b;
border: 1px solid #2a2a2a;
border-radius: 10px;
overflow: hidden;
}
.ha-filetabs {
display: flex;
background: #161616;
border-bottom: 1px solid #2a2a2a;
}
.ha-filetab {
border: none;
background: transparent;
color: #8a8a8a;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
font-weight: 700;
padding: 0.6rem 1rem;
cursor: pointer;
border-bottom: 2px solid transparent;
transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.ha-filetab:hover { color: #e5e5e5; }
.ha-filetab.ha-tab-on {
color: #ffffff;
border-bottom-color: #5b8def;
background: #0b0b0b;
}
.ha-code {
padding: 1rem 1.8rem 1rem 0.9rem;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
line-height: 1.85;
overflow-x: auto;
}
.ha-codepane { display: none; }
.ha-codepane.ha-pane-on { display: block; }
.ha-line { display: block; white-space: pre; color: #8a8a8a; padding: 0.05rem 0.4rem; }
.ha-tag { color: #60a5fa; font-weight: 700; }
.ha-attr { color: #f2b96b; }
.ha-str { color: #9ece6a; }
.ha-sel { color: #f472b6; font-weight: 700; }
.ha-prop { color: #c586c0; }
.ha-val { color: #ce9178; }
.ha-pos-val { color: #ffd166; font-weight: 800; }
.ha-extra-line { display: none; }
.ha-extra-line.ha-show { display: block; }
.ha-toggle {
display: flex;
background: var(--paper-alt);
border: 1px solid var(--line);
border-radius: 999px;
padding: 0.25rem;
gap: 0.25rem;
}
.ha-toggle button {
flex: 1;
border: none;
background: transparent;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 0.76rem;
font-weight: 700;
padding: 0.55rem 0.6rem;
border-radius: 999px;
cursor: pointer;
transition: background 0.2s ease, color 0.2s ease;
}
.ha-toggle button.ha-on { background: var(--accent); color: #fff; }
.ha-browser {
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: var(--paper);
}
.ha-browser-bar {
background: var(--paper-alt);
padding: 0.5rem 0.7rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid var(--line);
}
.ha-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.ha-tab {
background: var(--paper);
border: 1px solid var(--line);
border-bottom: none;
border-radius: 6px 6px 0 0;
font-size: 0.72rem;
color: var(--ink-soft);
padding: 0.25rem 0.6rem;
}
.ha-urlrow {
background: var(--paper-alt);
padding: 0.35rem 0.7rem 0.6rem;
font-size: 0.72rem;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
}
.ha-screen {
background: #ffffff;
color: #111;
padding: 1.2rem 1.4rem 1.6rem;
font-family: Georgia, "Times New Roman", serif;
position: relative;
min-height: 260px;
}
.ha-container {
width: 260px;
height: 200px;
margin: 30px auto 0 20px;
border: 2px dashed #999;
position: static;
transition: border-color 0.3s ease;
}
.ha-container.ha-positioned {
position: relative;
border-color: var(--accent);
}
.ha-container-label {
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 0.62rem;
color: #999;
position: absolute;
top: 2px;
left: 4px;
}
.ha-out-box {
width: 120px;
height: 80px;
background-color: salmon;
font-size: 0.82rem;
padding: 0.3rem 0.4rem;
box-sizing: border-box;
position: absolute;
top: 40px;
left: 60px;
transition: top 0.3s ease, left 0.3s ease;
}
.ha-note {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: 0.78rem;
color: var(--ink-soft);
}
</style>
</head>
<body>
<div class="infographic-absolutepos" id="ha-root">
<div class="ha-inner">
<div class="ha-layout">
<div class="ha-code-wrap">
<div class="ha-filetabs">
<button class="ha-filetab ha-tab-on" id="tab-html">index.html</button>
<button class="ha-filetab" id="tab-css">style.css</button>
</div>
<div class="ha-code">
<div class="ha-codepane ha-pane-on" id="pane-html">
<span class="ha-line"><<span class="ha-tag">div</span> <span class="ha-attr">class</span>=<span class="ha-str">"container"</span>></span>
<span class="ha-line"> <<span class="ha-tag">div</span> <span class="ha-attr">class</span>=<span class="ha-str">"box"</span>>I'm absolutely positioned</<span class="ha-tag">div</span>></span>
<span class="ha-line"></<span class="ha-tag">div</span>></span>
</div>
<div class="ha-codepane" id="pane-css">
<span class="ha-line ha-extra-line ha-show" id="line-container-open"><span class="ha-sel">.container</span> {</span>
<span class="ha-line ha-extra-line" id="line-container-pos"> <span class="ha-prop">position</span>: <span class="ha-pos-val">relative</span>;</span>
<span class="ha-line ha-extra-line ha-show" id="line-container-close">}</span>
<span class="ha-line"><span class="ha-sel">.box</span> {</span>
<span class="ha-line"> <span class="ha-prop">width</span>: <span class="ha-val">150px</span>;</span>
<span class="ha-line"> <span class="ha-prop">height</span>: <span class="ha-val">100px</span>;</span>
<span class="ha-line"> <span class="ha-prop">background-color</span>: <span class="ha-val">salmon</span>;</span>
<span class="ha-line"> <span class="ha-prop">position</span>: <span class="ha-pos-val">absolute</span>;</span>
<span class="ha-line"> <span class="ha-prop">top</span>: <span class="ha-val">50px</span>;</span>
<span class="ha-line"> <span class="ha-prop">left</span>: <span class="ha-val">100px</span>;</span>
<span class="ha-line">}</span>
</div>
</div>
</div>
<div class="ha-toggle">
<button class="ha-on" id="btn-noancestor">No positioned ancestor</button>
<button id="btn-ancestor">Container has position: relative</button>
</div>
<div class="ha-browser">
<div class="ha-browser-bar">
<span class="ha-dot"></span><span class="ha-dot"></span><span class="ha-dot"></span>
<div class="ha-tab">🌐 127.0.0.1:5500/html</div>
</div>
<div class="ha-urlrow">127.0.0.1:5500/html</div>
<div class="ha-screen">
<div class="ha-container" id="container">
<span class="ha-container-label">.container</span>
<div class="ha-out-box" id="out-box">I'm absolutely positioned</div>
</div>
</div>
</div>
<div class="ha-note" id="note-out">With no positioned ancestor anywhere up the tree, <code>top</code>/<code>left</code> measure from the viewport itself — the dashed <code>.container</code> is ignored entirely, which is why the box lands outside it.</div>
</div>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('ha-root');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
(function () {
const tabHtml = document.getElementById('tab-html');
const tabCss = document.getElementById('tab-css');
const paneHtml = document.getElementById('pane-html');
const paneCss = document.getElementById('pane-css');
tabHtml.addEventListener('click', () => {
tabHtml.classList.add('ha-tab-on');
tabCss.classList.remove('ha-tab-on');
paneHtml.classList.add('ha-pane-on');
paneCss.classList.remove('ha-pane-on');
});
tabCss.addEventListener('click', () => {
tabCss.classList.add('ha-tab-on');
tabHtml.classList.remove('ha-tab-on');
paneCss.classList.add('ha-pane-on');
paneHtml.classList.remove('ha-pane-on');
});
const btnNo = document.getElementById('btn-noancestor');
const btnYes = document.getElementById('btn-ancestor');
const container = document.getElementById('container');
const box = document.getElementById('out-box');
const note = document.getElementById('note-out');
const linePos = document.getElementById('line-container-pos');
btnNo.addEventListener('click', () => {
btnNo.classList.add('ha-on');
btnYes.classList.remove('ha-on');
container.classList.remove('ha-positioned');
linePos.classList.remove('ha-show');
box.style.top = '40px';
box.style.left = '60px';
note.innerHTML = 'With no positioned ancestor anywhere up the tree, <code>top</code>/<code>left</code> measure from the viewport itself — the dashed <code>.container</code> is ignored entirely, which is why the box can land outside it.';
});
btnYes.addEventListener('click', () => {
btnYes.classList.add('ha-on');
btnNo.classList.remove('ha-on');
container.classList.add('ha-positioned');
linePos.classList.add('ha-show');
box.style.top = '50px';
box.style.left = '100px';
note.innerHTML = 'Now that <code>.container</code> has <code>position: relative</code>, it becomes the reference point — the same <code>top</code>/<code>left</code> values now measure from its own edges instead of the viewport.';
});
})();
</script>
</body>
</html>.demo {
font-family: system-ui, sans-serif;
padding: 16px;
}
.demo h1 {
color: #2563eb;
margin: 0 0 8px;
}
.demo p {
color: #4b5563;
margin: 0;
}document.querySelector('.demo h1')?.addEventListener('click', () => {
alert('Hello from live preview!');
});No positioned ancestor: The .box has position: absolute, but nothing above it in the tree has a position value other than static. So the browser skips past .container entirely and looks all the way up to the initial containing block — essentially the viewport. top: 50px; left: 100px means 50px down and 100px right from the page's top-left corner, not the container's.
Container has position: relative: Adding position: relative to .container doesn't move .container itself (no offsets were given to it) — but it does something more important: it makes .container a "positioned element." Now it becomes the nearest positioned ancestor for .box, so the same top: 50px; left: 100px gets measured from the container's own top-left corner instead of the page's. This is the classic pattern for "contain this absolutely-positioned thing inside its parent."
📌 Summary Table: position: absolute
Property | Effect |
|---|---|
| Takes element out of flow and positions it precisely |
Reference point | Nearest ancestor with |
Default reference | If no such ancestor, falls back to |
Common use cases | Tooltips, modals, badges, dropdowns, overlays, etc. |
📍 position: fixed
Positions the element relative to the viewport (browser window).
Doesn’t move when you scroll the page.
Removed from the normal document flow.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Fixed Position Anatomy</title>
<style>
.infographic-fixedpos {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
box-sizing: border-box;
margin: 0 auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
border-radius: 14px;
overflow: hidden;
}
.infographic-fixedpos[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
}
.ha-inner { padding: 0.5rem; }
.ha-layout { display: flex; flex-direction: column; gap: 1.2rem; }
.ha-code-wrap {
background: #0b0b0b;
border: 1px solid #2a2a2a;
border-radius: 10px;
overflow: hidden;
}
.ha-filetabs {
display: flex;
background: #161616;
border-bottom: 1px solid #2a2a2a;
}
.ha-filetab {
border: none;
background: transparent;
color: #8a8a8a;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
font-weight: 700;
padding: 0.6rem 1rem;
cursor: pointer;
border-bottom: 2px solid transparent;
transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.ha-filetab:hover { color: #e5e5e5; }
.ha-filetab.ha-tab-on {
color: #ffffff;
border-bottom-color: #5b8def;
background: #0b0b0b;
}
.ha-code {
padding: 1rem 1.8rem 1rem 0.9rem;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
line-height: 1.85;
overflow-x: auto;
}
.ha-codepane { display: none; }
.ha-codepane.ha-pane-on { display: block; }
.ha-line { display: block; white-space: pre; color: #8a8a8a; padding: 0.05rem 0.4rem; }
.ha-tag { color: #60a5fa; font-weight: 700; }
.ha-attr { color: #f2b96b; }
.ha-str { color: #9ece6a; }
.ha-sel { color: #f472b6; font-weight: 700; }
.ha-prop { color: #c586c0; }
.ha-val { color: #ce9178; }
.ha-pos-val { color: #ffd166; font-weight: 800; }
.ha-comment { color: #5c6370; font-style: italic; }
.ha-browser {
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: var(--paper);
}
.ha-browser-bar {
background: var(--paper-alt);
padding: 0.5rem 0.7rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid var(--line);
}
.ha-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.ha-tab {
background: var(--paper);
border: 1px solid var(--line);
border-bottom: none;
border-radius: 6px 6px 0 0;
font-size: 0.72rem;
color: var(--ink-soft);
padding: 0.25rem 0.6rem;
}
.ha-urlrow {
background: var(--paper-alt);
padding: 0.35rem 0.7rem 0.6rem;
font-size: 0.72rem;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
}
/* Scrollable mock viewport — transform makes it a containing block for position:fixed,
so the fixed box sticks to THIS frame's corner instead of the whole page. */
.ha-scrollframe {
position: relative;
height: 220px;
overflow-y: scroll;
transform: translateZ(0);
background: #ffffff;
font-family: Georgia, "Times New Roman", serif;
}
.ha-scroll-content { padding: 1rem 1.2rem; }
.ha-scroll-content p { font-size: 0.85rem; margin: 0 0 0.8rem; color: #333; }
.ha-tall-spacer { height: 900px; }
.ha-out-box {
position: sticky;
top: 0;
float: right;
background-color: lightgreen;
color: #111;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: 0.8rem;
padding: 0.5rem 0.8rem;
border: 1px solid #333;
z-index: 1000;
}
.ha-note {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: 0.78rem;
color: var(--ink-soft);
}
</style>
</head>
<body>
<div class="infographic-fixedpos" id="ha-root">
<div class="ha-inner">
<div class="ha-layout">
<div class="ha-code-wrap">
<div class="ha-filetabs">
<button class="ha-filetab ha-tab-on" id="tab-html">index.html</button>
<button class="ha-filetab" id="tab-css">style.css</button>
</div>
<div class="ha-code">
<div class="ha-codepane ha-pane-on" id="pane-html">
<span class="ha-line"><<span class="ha-tag">body</span>></span>
<span class="ha-line"> <<span class="ha-tag">div</span> <span class="ha-attr">class</span>=<span class="ha-str">"box"</span>>Fixed to the top-right corner</<span class="ha-tag">div</span>></span>
<span class="ha-line"> <<span class="ha-tag">p</span>>Scroll down to see the box stay fixed at top-right.</<span class="ha-tag">p</span>></span>
<span class="ha-line"> <<span class="ha-tag">div</span> <span class="ha-attr">style</span>=<span class="ha-str">"height: 1500px"</span>></<span class="ha-tag">div</span>></span>
<span class="ha-line ha-comment"> <!-- just to enable scrolling --></span>
<span class="ha-line"></<span class="ha-tag">body</span>></span>
</div>
<div class="ha-codepane" id="pane-css">
<span class="ha-line"><span class="ha-sel">.box</span> {</span>
<span class="ha-line"> <span class="ha-prop">position</span>: <span class="ha-pos-val">fixed</span>;</span>
<span class="ha-line"> <span class="ha-prop">top</span>: <span class="ha-val">0</span>;</span>
<span class="ha-line"> <span class="ha-prop">right</span>: <span class="ha-val">0</span>;</span>
<span class="ha-line"> <span class="ha-prop">background-color</span>: <span class="ha-val">lightgreen</span>;</span>
<span class="ha-line"> <span class="ha-prop">padding</span>: <span class="ha-val">10px 20px</span>;</span>
<span class="ha-line"> <span class="ha-prop">z-index</span>: <span class="ha-val">1000</span>; <span class="ha-comment">/* stays on top */</span></span>
<span class="ha-line">}</span>
</div>
</div>
</div>
<div class="ha-browser">
<div class="ha-browser-bar">
<span class="ha-dot"></span><span class="ha-dot"></span><span class="ha-dot"></span>
<div class="ha-tab">🌐 Fixed Position Example</div>
</div>
<div class="ha-urlrow">127.0.0.1:5500/html</div>
<div class="ha-scrollframe">
<div class="ha-scroll-content">
<div class="ha-out-box">Fixed to the top-right corner</div>
<p>Scroll down inside this frame to see the box stay pinned at top-right.</p>
<div class="ha-tall-spacer"></div>
<p>Still here — the box never moved.</p>
</div>
</div>
</div>
<div class="ha-note">This frame really scrolls. Genuine <code>position: fixed</code> always pins to the whole browser window, not a small boxed-off area like this — so to demonstrate the "stays put while scrolling" effect cleanly inside this card, the box actually uses <code>position: sticky</code> here, which is the smooth, glitch-free way to pin something within a specific scrollable container. The real code above still uses <code>fixed</code>, which is exactly what you'd want on an actual full page.</div>
</div>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('ha-root');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
(function () {
const tabHtml = document.getElementById('tab-html');
const tabCss = document.getElementById('tab-css');
const paneHtml = document.getElementById('pane-html');
const paneCss = document.getElementById('pane-css');
tabHtml.addEventListener('click', () => {
tabHtml.classList.add('ha-tab-on');
tabCss.classList.remove('ha-tab-on');
paneHtml.classList.add('ha-pane-on');
paneCss.classList.remove('ha-pane-on');
});
tabCss.addEventListener('click', () => {
tabCss.classList.add('ha-tab-on');
tabHtml.classList.remove('ha-tab-on');
paneCss.classList.add('ha-pane-on');
paneHtml.classList.remove('ha-pane-on');
});
})();
</script>
</body>
</html>.demo {
font-family: system-ui, sans-serif;
padding: 16px;
}
.demo h1 {
color: #2563eb;
margin: 0 0 8px;
}
.demo p {
color: #4b5563;
margin: 0;
}document.querySelector('.demo h1')?.addEventListener('click', () => {
alert('Hello from live preview!');
});📌position: sticky
Combines features of both relative and fixed positioning.
The element behaves like relative until it crosses a certain scroll threshold.
After that, it behaves like fixed — sticking to a defined offset (like top: 0).
Commonly used for sticky headers, sidebars, or table column labels.
Needs a scrollable ancestor (usually the viewport or a container).
The sticky element will only stick within its parent.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sticky Position Anatomy</title>
<style>
.infographic-stickypos {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
box-sizing: border-box;
margin: 0 auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--paper);
color: var(--ink);
border-radius: 14px;
overflow: hidden;
}
.infographic-stickypos[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
}
.ha-inner { padding: 0.5rem; }
.ha-layout { display: flex; flex-direction: column; gap: 1.2rem; }
.ha-code-wrap {
background: #0b0b0b;
border: 1px solid #2a2a2a;
border-radius: 10px;
overflow: hidden;
}
.ha-filetabs {
display: flex;
background: #161616;
border-bottom: 1px solid #2a2a2a;
}
.ha-filetab {
border: none;
background: transparent;
color: #8a8a8a;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
font-weight: 700;
padding: 0.6rem 1rem;
cursor: pointer;
border-bottom: 2px solid #5b8def;
}
.ha-code {
padding: 1rem 1.8rem 1rem 0.9rem;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 0.78rem;
line-height: 1.85;
overflow-x: auto;
}
.ha-line { display: block; white-space: pre; color: #e5e5e5; padding: 0.05rem 0.4rem; }
.ha-tag { color: #60a5fa; font-weight: 700; }
.ha-attr { color: #f2b96b; }
.ha-str { color: #9ece6a; }
.ha-sel { color: #f472b6; font-weight: 700; }
.ha-prop { color: #c586c0; }
.ha-val { color: #ffd166; font-weight: 700; }
.ha-browser {
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: var(--paper);
}
.ha-browser-bar {
background: var(--paper-alt);
padding: 0.5rem 0.7rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid var(--line);
}
.ha-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.ha-tab {
background: var(--paper);
border: 1px solid var(--line);
border-bottom: none;
border-radius: 6px 6px 0 0;
font-size: 0.72rem;
color: var(--ink-soft);
padding: 0.25rem 0.6rem;
}
.ha-urlrow {
background: var(--paper-alt);
padding: 0.35rem 0.7rem 0.6rem;
font-size: 0.72rem;
color: var(--ink-soft);
font-family: "SFMono-Regular", Consolas, monospace;
}
.ha-scrollframe {
position: relative;
height: 260px;
overflow-y: scroll;
background: #ffffff;
font-family: Georgia, "Times New Roman", serif;
}
.ha-scroll-content { padding: 1rem 1.2rem; }
.ha-scroll-content h2 { font-size: 1rem; margin: 0.8rem 0 0.4rem; }
.ha-scroll-content p { font-size: 0.85rem; margin: 0 0 0.8rem; color: #333; line-height: 1.5; }
.ha-sticky-box {
position: sticky;
top: 0;
background-color: lightgreen;
color: #111;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: 0.85rem;
padding: 0.6rem 0.8rem;
border: 1px solid #333;
margin: 0.6rem 0;
}
.ha-note {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: 0.78rem;
color: var(--ink-soft);
}
</style>
</head>
<body>
<div class="infographic-stickypos" id="ha-root">
<div class="ha-inner">
<div class="ha-layout">
<div class="ha-code-wrap">
<div class="ha-filetabs">
<button class="ha-filetab">index.html</button>
</div>
<div class="ha-code">
<span class="ha-line"><<span class="ha-tag">style</span>></span>
<span class="ha-line"> <span class="ha-sel">.sticky</span> {</span>
<span class="ha-line"> <span class="ha-prop">position</span>: <span class="ha-val">sticky</span>;</span>
<span class="ha-line"> <span class="ha-prop">top</span>: <span class="ha-val">0</span>;</span>
<span class="ha-line"> <span class="ha-prop">background-color</span>: <span class="ha-val">lightgreen</span>;</span>
<span class="ha-line"> <span class="ha-prop">padding</span>: <span class="ha-val">10px</span>;</span>
<span class="ha-line"> }</span>
<span class="ha-line"></<span class="ha-tag">style</span>></span>
<span class="ha-line"> </span>
<span class="ha-line"><<span class="ha-tag">h2</span>>Sticky Element: Scroll Down to See the Effect</<span class="ha-tag">h2</span>></span>
<span class="ha-line"><<span class="ha-tag">p</span>>Scroll down this page to see how sticky positioning works.</<span class="ha-tag">p</span>></span>
<span class="ha-line"><<span class="ha-tag">div</span> <span class="ha-attr">class</span>=<span class="ha-str">"sticky"</span>></span>
<span class="ha-line"> I will stick to the screen when you reach my scroll position</span>
<span class="ha-line"></<span class="ha-tag">div</span>></span>
</div>
</div>
<div class="ha-browser">
<div class="ha-browser-bar">
<span class="ha-dot"></span><span class="ha-dot"></span><span class="ha-dot"></span>
<div class="ha-tab">🌐 127.0.0.1:5500/html</div>
</div>
<div class="ha-urlrow">127.0.0.1:5500/html</div>
<div class="ha-scrollframe">
<div class="ha-scroll-content">
<h2>Sticky Element: Scroll Down to See the Effect</h2>
<p>Scroll down this frame to see how sticky positioning works.</p>
<div class="ha-sticky-box">I will stick to the screen when you reach my scroll position</div>
<p>Some example text..</p>
<h2>Scroll back up again to "remove" the sticky position.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet.</p>
<p>Mauris ante ligula, facilisis sed ornare eu, lobortis in odio. Praesent convallis urna a lacus interdum ut hendrerit risus congue. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis.</p>
<p>Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta. Cras ac leo purus. Mauris quis diam velit.</p>
<p>More content, just to give the frame plenty of room to scroll through and demonstrate the effect clearly.</p>
</div>
</div>
</div>
<div class="ha-note">Scroll the frame above — the green box floats along normally at first, then locks to the top the moment it reaches it, and stays there until its parent's content runs out from under it. That's <code>position: sticky</code>: a hybrid of <code>relative</code> (while scrolling past) and <code>fixed</code> (once it hits its <code>top</code> offset).</div>
</div>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('ha-root');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
</script>
</body>
</html>.demo {
font-family: system-ui, sans-serif;
padding: 16px;
}
.demo h1 {
color: #2563eb;
margin: 0 0 8px;
}
.demo p {
color: #4b5563;
margin: 0;
}document.querySelector('.demo h1')?.addEventListener('click', () => {
alert('Hello from live preview!');
});🕛 Quick Visual Reminder
Type | Relative To | Affects Flow? | Scrolls with Page? |
|---|---|---|---|
Static | Normal document flow | ✅ Yes | ✅ Yes |
Relative | Itself (original spot) | ✅ Yes | ✅ Yes |
Absolute | Closest positioned parent | ❌ No | ✅ Yes |
Fixed | Viewport (browser) | ❌ No | ❌ No |
Sticky | Scrolls until offset, then fixed | ✅ Yes (initially) | ✅ Yes (partially) |