The flexbox layout mode has completely redefined layouts in CSS. It is not just a property but a whole new module.
The CSS3 Flexible Box, or flexbox, arranges the elements on a page such that they would accommodate themselves according to varying screen sizes and varying display devices. The flexbox model provides an improvement over the block model in many aspects such as it has disabled floats, also the flex container's margins do not collapse with the margins of child contents. The only prime characteristic of the flex layout is the ability to adjust the dimensions of its children to fill the available space in the best way possible on different screen sizes.
The flexbox model is definitely easier to use. Child elements can be made to have flexible dimensions to adjust to the various display size. Also, positioning child elements have become much easier. Complex layouts can be achieved easily with a cleaner and simpler code.
The most important aspect of the flex layout is its ability to adjust the items' dimensions to fill the screen space on any device accordingly.
Flexbox layout is appropriate for the components that have to change orientation, resize, stretch, shrink, flips from vertical to horizontal, and so on.
To deploy this, set the display property as follows:
As we do so, the parent element will be defined as a flex container and its immediate children will be defined as flex items. The flex value makes the parent element a block-level element whereas the inline-flex value makes the parent element an inline-level element.
The following figure will explain the main idea behind the flex layout.
The flex layout constitutes of 2 parts :
1. Parent container (flex container)
2. Its immediate children (flex items)
The various browser support is given under :
Internet Explorer 11+
Safari 6.1+ (prefixed with -webkit-)
I am providing a very simple example showing how flexbox has the ability to automatically change the layout for different screen sizes. In this example, the elements change their sizes and also the order in which they appear. Flexbox makes this very simple.