freeCodeCamp/guide/english/css/layout/flexbox/index.md

2.7 KiB
Raw Blame History

title
Flexbox

Flexbox

Flexbox is a new way to structure content in CSS3. It provides a wonderful way to create responsive websites that work well across different screen sizes and order content.

There are 3 simple steps to use flexbox.

  1. Convert parent container to a flex container by using display:flex; in the css section
  2. Adjust arrangement of different containers using flex-direction
  3. Adjust individual items by using properties like justify-content, align-items etc.

The Flexbox Layout aims at providing a more efficient way to lay out, align and distribute space among items in a container, even when their size is unknown and/or dynamic (thus the word "flex").The main idea behind the flex layout is to give the container the ability to alter its items' width/height (and order) to best fill the available space.

flexUsage

  • main-axis: The main axis of a flex container is the primary axis along which flex items are laid out. Beware, it is not necessarily horizontal; it depends on the flex-direction property (see below).
  • main-start | main-endThe flex items are placed within the container starting from main-start and going to main-end.
  • :
  • main size: A flex item's width or height, whichever is in the main dimension, is the item's main size. The flex item's main size property is either the width or height property, whichever is in the main dimension.
  • cross axis: The axis perpendicular to the main axis is called the cross axis. Its direction depends on the main axis direction.
  • cross-start | cross-end: Flex lines are filled with items and placed into the container starting on the cross-start side of the flex container and going toward the cross-end side.
  • cross size: The width or height of a flex item, whichever is in the cross dimension, is the item's cross size. The cross size property is whichever of width or height that is in the cross dimension.

More Information:

This is a great article to read up to understand more about flexbox This is a highly recommended practical guide that illustrate the different flex properties applied to the flex container and th flex items: https://css-tricks.com/snippets/css/a-guide-to-flexbox/