The Flexbox layout provides a highly efficient way to organize, align, and distribute space among items within a container. It allows elements to expand and fill available free space or shrink to prevent overflow.
The flexbox layout is direction-agnostic as opposed to the regular layouts. It is:
A Flex Container is the parent element and the direct children of that element become Flex Items.
To enable the Flex display for any element that contains other elements inside it:
Alternatively, you can add a Flex element to your page from the Elements Panel to start from scratch.
The flex-direction property specifies the direction of the flex items. It can be set to:
The cross-axis is the perpendicular axis to the main axis within a flex container. The main axis is defined by the flex-direction property, which can be set to a row or column.
For example, if the flex-direction is set to row, then the main axis will be horizontal, and the cross-axis will be vertical.
The flex-wrap property sets whether flex items are forced onto one line or can wrap onto multiple lines.
If you have added flex-wrap: wrap to your flex container and have multiple flex lines, you can use align-content to align your flex lines on the cross axis.
The align-content property modifies the behavior of the flex-wrap property. It is similar to align-items, but instead of aligning flex items, it aligns flex lines.
📝 Note: There must be multiple lines of items for this property to have any effect!
Position
Baseline
Distributed
Due to Flexbox alignment, elements are centered, causing child elements to overflow on the right and left sides.
The problem is that the overflowing area on the left side is past the viewport’s start edge. You can not scroll to this area hence leads to data loss.
To handle overflowing situations, the align-items property can help:
The global values can be used for various Flexbox properties:
The gap
property explicitly controls the space between flex items. It applies spacing only between items and not on the outer edges.
To align flex items vertically, select one of the following alignment options:
The justify property aligns flex items horizontally when they do not use all available space on the main axis.
To align flex items horizontally, select one of the following alignment options:
📝 Note: Many of these options can also be found on the Flex Controller. To access this controller, simply click on the blue settings icon on the flex element’s top-right corner.
A flex child is also referred to as a flex item. Here, you can control the order, alignment, and spacing of flex items within the flex container.
The align-self property controls the alignment of individual flex items along the cross-axis of the flex container. It applies only to individual flex items, whereas align-items applies to all flex items within the container.
Available Values for align-self:
The Order property controls the order in which flex items appear within the flex container.
By default, all flex items have an order value of 0, but you can change it to reorder items based on different screen sizes, create a responsive layout, or for accessibility reasons.
The order property accepts integer values, and you can assign a different order value to each flex item within the container. Flex items with lower order values appear first, followed by items with higher order values.
For example, if you set the order value of one flex item to -1 and another to 1, the flex item with the order value of -1 will appear first, followed by the flex item with an order value of 0, and then the flex item with an order value of 1.
In Flex Ratio, you can set the flex-basis, flex-grow, and flex-shrink properties to create flexible and responsive layouts.
flex-basis
This property sets the initial size of a flex item along the main axis of the flex container. It specifies the default size of the flex item before any remaining space is distributed according to the flex-grow and flex-shrink properties.
The flex-basis property can be set to a length value, such as pixels or percentages, or it can be set to the auto keyword, which means the initial size of the item will be based on its content.
flex-grow
This property determines how much a flex item will grow when there is extra space available along the main axis. It accepts a unitless value that represents the proportion of available space that the flex item should take up relative to other flex items within the same flex container.
flex-shrink
This property controls how much a flex item will shrink when there is not enough space to accommodate all the items within the flex container. It also accepts a unitless value that represents the proportion of space that should be taken away from the item when
Was this page helpful?
Our website uses cookies to improve your browsing experience on our website. By continuing to use this website, you agree to their use. For details, please check our Privacy Policy.
Experience Droip in Action – Explore a live-built page and see the power of our builder in action.
Explore Live