CSS Flexbox Tutorial
When constructing a house, a blueprint acts as a crucial guide. Similarly, in the realm of web development, we require a blueprint to achieve well-organized websites. Enter Flexbox – the ultimate blueprint for web layouts. The Flexbox model not only simplifies the arrangement of website content but also enables us to establish structures that adapt flawlessly to diverse devices, ensuring responsive designs. With Flexbox, crafting visually appealing and user-friendly websites becomes a seamless process, guaranteeing an optimal browsing experience across various screen sizes.
Flex Property | Values | Description | Example Usage |
---|---|---|---|
display: flex; | flex | Sets the element as a flex container, enabling flex properties on its child elements. | <div style="display: flex;">... |
justify-content | flex-start, flex-end, center, space-between, space-around | Specifies how flex items are distributed along the main axis of the flex container.
|
<div style="justify-content: flex-start;">... |
align-items | flex-start, flex-end, center, baseline, stretch | Specifies how flex items are aligned along the cross axis of the flex container.
|
<div style="align-items: flex-start;">... |
flex-direction | row, row-reverse, column, column-reverse | Specifies the direction of the main axis and cross axis within the flex container.
|
<div style="flex-direction: row;">... |
flex-wrap | nowrap, wrap, wrap-reverse | Specifies whether flex items should wrap or stay on a single line.
|
<div style="flex-wrap: nowrap;">... |
flex-grow | number | Specifies the ability for a flex item to grow if necessary within the flex container. | <div style="flex-grow: 1;">... |
flex-shrink | number | Specifies the ability for a flex item to shrink if necessary within the flex container. | <div style="flex-shrink: 1;">... |
flex-basis | length, auto | Specifies the initial size of a flex item before any remaining space is distributed.
|
<div style="flex-basis: 100px;">... |
align-self | `flex-start`, `flex-end`, `center`, `stretch`, and `baseline` | The `align-self` property in CSS is used in Flexbox to individually control the alignment of a specific flex item within its container along the cross-axis. It has values like `flex-start`, `flex-end`, `center`, `stretch`, and `baseline`, providing flexibility to customize item alignment independently. | <div style="align-self: flex-start;">... |
order | takes a number/integer. Lower numbers appear first in the container, then bigger numbers appear last |
The Flexbox The Here’s a brief summary of how
|
<div style="order: 1;">... |