Hey There! Some links on this page are affiliate links which means that, if you choose to make a purchase, I will earn a small commission at no extra cost to you. I greatly appreciate your support!
Advertisement

Illustration of CSS3 Flexbox

How CSS3 Flex model works?

The CSS Flexible Box Layout, or “Flexbox,” is a layout mode in CSS3 that makes it easier to design flexible responsive layout structure without using float or positioning. It works by defining a flex container, which can contain multiple flex items. The flex container can then control the layout and alignment of the flex items within it.

The basic concepts of flexbox are:

  • A flex container is defined using the display: flex or display: inline-flex properties on an element.
  • The flex items are the direct children of the flex container.
  • The flex container can control the layout of the flex items in the main axis (horizontally by default) and the cross axis (vertically by default).
  • The flex container can also control the alignment and distribution of space between the flex items.

Some of the main flex container properties include:

  • flex-direction: controls the main axis, which can be set to row, row-reverse, column, or column-reverse.
  • justify-content: controls the alignment of items along the main axis, which can be set to flex-start, flex-end, center, space-between, or space-around.
  • align-items: controls the alignment of items along the cross axis, which can be set to flex-start, flex-end, center, baseline, or stretch.

Some of the main flex item properties include:

  • flex-basis: controls the initial size of the item along the main axis.
  • flex-grow: controls how much the item will grow relative to the other items in the container.
  • flex-shrink: controls how much the item will shrink relative to the other items in the container.
  • align-self: controls the alignment of a single item along the cross axis.

Using flexbox, you can create complex layout easily and efficiently, like a responsive grid system, aligning items vertically and horizontally, adjusting items as per available space, etc. It’s widely supported by all modern browsers, and it’s a great way to build responsive web pages.

Advertisement

Pin It on Pinterest