📌 1. Flexbox Layout
- Principle: Flexbox is a layout module that allows for flexible and responsive design by aligning items in a single line (flex-direction) and distributing space between them.
- Use Cases: Ideal for creating navigation bars, card layouts, and form elements.
- Example Code:
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
📌 2. Grid Layout
- Principle: CSS Grid creates a two-dimensional grid system for complex layouts, enabling precise control over rows and columns.
- Use Cases: Perfect for dashboards, product listings, and multi-column content sections.
- Example Code:
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
📌 3. Floating Layout
- Principle: Uses
float
property to position elements next to each other, commonly used for older layouts. - Use Cases: For creating image galleries or aligning text around images.
- Example Code:
.float-container {
overflow: hidden;
}
.float-item {
float: left;
margin: 10px;
}
📌 4. Absolute Positioning
- Principle: Positions elements relative to the nearest positioned ancestor, allowing for precise placement.
- Use Cases: For overlays, modals, or fixed-position components like sidebars.
- Example Code:
.absolute-box {
position: absolute;
top: 20px;
left: 30px;
}
📌 5. Responsive Design
- Principle: Utilizes media queries and flexible units (e.g.,
%
,vw
,vh
) to adapt layouts to different screen sizes. - Use Cases: Ensuring optimal viewing experience across devices.
- Example Code:
@media (max-width: 768px) {
.responsive-container {
flex-direction: column;
}
}
For deeper exploration of CSS Grid, visit Learn more about CSS Grid. 🚀