CHAPTER 06
Beginner
CSS Display, Positioning, and Layout Basics
Updated: May 10, 2026
5 min read
# CSS Display & Positioning
1. Introduction
Before Flexbox and Grid,display and position were the only ways to build layouts. Even today, mastering these fundamentals is critical for floating elements, sticky headers, and basic alignment.
2. Learning Objectives
-
Understand
block,inline, andinline-block.
-
Master
position: relative,absolute,fixed, andsticky.
-
Use
z-indexto stack overlapping elements.
3. Detailed Explanations
The Display Property
-
block: Takes up the full width available. Starts on a new line. (e.g.,
<div>,<p>)
-
inline: Takes up only as much width as necessary. Does not start on a new line. Cannot have width/height. (e.g.,
<span>,<a>)
- inline-block: Like inline, but allows you to set width and height!
- none: Hides the element entirely from the layout.
css
Static vs Relative Positioning
- static: The default. Elements flow naturally.
-
relative: Elements flow naturally, BUT you can nudge them using
top,right,bottom,left.
css
Absolute Positioning
Removes the element from the normal document flow. It positions itself relative to its closest positioned ancestor (an ancestor withposition: relative).
css
Fixed and Sticky Positioning
- fixed: Pins to the browser window. Survives scrolling.
-
sticky: Acts like
relativeuntil you scroll past it, then it acts likefixed.
css
4. Mini Project: Sticky Navbar
html
css
5. MCQs
Q1: Which position value removes an element from the normal document flow and anchors it to a parent? A) static B) relative C) absolute D) sticky *Answer: C*6. Summary
Useinline-block when you need elements side-by-side but need width/height. Use position: absolute for badges, tooltips, and overlays. Use position: sticky for modern navigation bars!