css flex box

CSS Flexbox

Flexbox (Flexible Box Layout) is a powerful CSS layout module that allows elements to be aligned and distributed efficiently inside a container, even when their sizes are unknown or dynamic. It is especially useful for responsive design.

Basic Flexbox Structure

To enable Flexbox, set display: flex; on a container.

.container {

    display: flex;

}

Main Flexbox Properties

1. Flex Container Properties

These properties apply to the parent (flex container).

Example:

.container {

    display: flex;

    flex-direction: row;

    justify-content: space-between;

    align-items: center;

}

2. Flex Item Properties

These properties apply to individual flex items inside a container.

Example:

.item {

    flex-grow: 1;

    flex-basis: 200px;

    align-self: flex-start;

}

Flexbox Example

<div class=”container”>

<div class=”item”>Item 1</div>

<div class=”item”>Item 2</div>

<div class=”item”>Item 3</div>

</div>

.container {

    display: flex;

    justify-content: space-around;

    align-items: center;

}

.item {

    width: 100px;

    height: 50px;

    background: lightblue;

}

Leave a Comment

Your email address will not be published. Required fields are marked *