CSS Positioning and Layout Techniques
📐 CSS Positioning & Layout Techniques
CSS provides multiple positioning schemes and modern layout models for precise and responsive design control.
🧭 Positioning Schemes
- 🔹
static
: Default; elements follow normal document flow - 🔸
relative
: Positioned relative to their normal position - 🔧
absolute
: Positioned relative to the nearest positioned ancestor - 📌
fixed
: Positioned relative to the viewport (stays in place while scrolling) - 🧲
sticky
: Switches between relative and fixed based on scroll position
📦 Modern Layout Techniques
🔄 Flexbox
- 📏 One-dimensional layout (row or column)
- 💡 Ideal for distributing space and aligning items within a container
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
🧮 CSS Grid
- 🧱 Two-dimensional layout (rows and columns)
- 🌐 Perfect for complex, grid-based layouts
.container {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 20px;
}
✅ Mastering positioning and layout techniques is essential for building structured, scalable, and responsive web designs.