Sub topic 1
How Elements Flow by Default
Prerequisites
You should know basic HTML structure, CSS selectors, the box model, and length units such as px, %, and rem.
How Elements Flow by Default
The browser places elements in normal flow, the default layout process. Block elements, such as div and p, usually start on a new line and take the available width. Inline elements, such as span and a, share a line when space is available.
Each element reserves space for itself. Later elements are placed after that reserved space. This makes normal flow responsive because surrounding content can move when an element changes size.
The `position` Property at a Glance
The position property changes how an element participates in layout.
staticis the default. Offset properties do not move it.relativekeeps its original space but allows visual movement.absoluteremoves the element from normal flow and positions it against a containing block.fixedremoves it from normal flow and usually positions it against the viewport.stickybehaves normally until a scroll threshold is reached, then stays attached within its scroll container.
Placing Elements with Offsets
The offset properties are top, right, bottom, and left. They describe distances from relevant edges. The inset shorthand sets all four at once.
Offsets have no effect on a static element. Their meaning depends on the chosen position value and its containing block.
.notice {
position: relative;
top: 10px;
left: 20px;
}
.panel {
position: absolute;
inset: 0;
}Relative Positioning: Shifting Without Leaving the Flow
A relatively positioned element is drawn at a shifted location, but its original space remains reserved. This prevents following content from filling the gap.
.box {
position: relative;
top: 10px;
left: 20px;
}The box appears 10 pixels lower and 20 pixels to the right. Its neighbors still lay out as if it had not moved.
Exercise
What happens to the space reserved for an element when position: relative moves it?
Show answer
The original space remains reserved, even though the element is painted in a new location.