CSS: Layout

Learn how to structure and position elements using CSS layout techniques.

CSS Layout Techniques

CSS provides various techniques to create layouts:

Example: Flexbox Layout

/* Example */
.container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.item {
    flex: 1;
    margin: 10px;
}
        

This example creates a flexible layout with evenly spaced items.

Example: Grid Layout

/* Example */
.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.grid-item {
    background-color: #f0f0f0;
    padding: 20px;
}
        

This example creates a grid layout with three equal columns and spacing between items.

Practice

Try experimenting with layout techniques:

Continue Learning

Quick Check

Which layout system is two-dimensional and great for rows and columns?