Home Services Portfolio Experience Blog Testimonials
Home Services Portfolio Experience Blog Testimonials

How To Use Flexbox

All flex-direction settings

definition and explanation of the flexrow settings

flex basis–this has a higher specificity rating than width. It is like the new version of setting the width. When flax basis is used, the normal width setting is ignored. But it doesn’t ignore min-width and max-width values. When the focus is vertical instead of horizontal, it will deal with height.

All justify-content settings

picture of some justify content options

align-items–used to align flex items along the cross axis of a flex container. The cross axis is perpendicular to the main axis, which is determined by the flex-direction property.

Align-Items Flex Direction Properties

Picture of some flex direction properties

align-self–used to align a specific flex item along the cross axis of its flex container, independently of the alignment defined by the align-items property on the flex container.

All Align-Self Properties

some align-self properties

align-content–is used to distribute space between and around flex lines when there is extra space along the cross-axis, which is the axis perpendicular to the main axis. This property is similar to align-items, but whereas align-items affects individual flex items on the cross-axis, align-content affects the space between and around multiple flex lines.

Align-Content Properties

It only applies when there is more than one line of flex items (i.e., when flex-wrap is set to wrap or wrap-reverse).

It controls the distribution of space in the cross-axis direction, which is the vertical direction in a row-direction flex container, and the horizontal direction in a column-direction flex container.

The align-content property can take several values:

1. flex-start: Aligns the flex lines to the start of the flex container’s cross-axis.

2. flex-end: Aligns the flex lines to the end of the flex container’s cross-axis.

3. center: Centers the flex lines along the cross-axis.

4. space-between: Distributes the flex lines evenly within the flex container along the cross-axis, such that there is a half-size space at the start and end of the flex container.

5. space-around: Similar to space-between, but the spaces between the flex lines are equal, and there is also a half-size space on either end of the flex container.

6. space-evenly: Distributes the flex lines so that the space between each line and the flex container edges is equal.

7. stretch (default): If the flex lines don’t fill the flex container, this value stretches the lines to fill the remaining space along the cross-axis.

flex-grow–specifies how a flex item should grow relative to the rest of the flex items in the flex container when there is extra space available along the main axis

Flex-Grow Properties

flex-shrink–determines how a flex item should shrink relative to the rest of the flex items in the flex container when there isn’t enough space on the main axis to accommodate all flex items at their default or current size.

Flex-Shrink Properties

Default Value: The default value of flex-shrink is 1, which means that flex items will shrink if necessary to fit into the flex container.

order–specifies the order in which flex items are laid out in their flex container. By default, flex items are laid out in the order they appear in the HTML source code. However, the order property allows you to change the visual order without having to change the actual order of the elements in the document.

Order Properties

The order property accepts integer values (...-3-2-10123, …), where:

Flex-Wrap Properties

some flex-wrap properties

Flex-Basis In More Detail

flex-basis is a property that defines the initial main size of a flex item before free space is distributed according to the flex factors. It is one of the three main properties that control the layout of flex items, along with flex-grow and flex-shrink.

1. flex-grow: This property specifies how much the flex item will grow relative to the rest of the flex items in the flex container when there is positive free space (i.e., the container is larger than the total size of the flex items). A flex item can grow if its flex-grow factor is greater than 0.

2.flex-shrink: This property specifies how much the flex item will shrink relative to the rest of the flex items in the flex container when there is negative free space (i.e., the container is smaller than the total size of the flex items). A flex item can shrink if its flex-shrink factor is greater than 0.

3.flex-basis: This is the property that determines the initial size of the flex item along the main axis before any available space is distributed. The flex-basis can be set to several different values, including:

  • A specific size (e.g., 20px5em15%).
  • auto: The browser calculates the size of the flex item based on its content.
  • content: Similar to auto, but it may trigger wrapping if the content is too large.

The shorthand flex property allows you to specify flex-growflex-shrink, and flex-basis in one declaration. For example:

.flex-item { flex: 1 1 10px; /* This means flex-grow: 1, flex-shrink: 1, flex-basis: 10px */ }

Some CSS Shorthand Properties

Flexbox shorthand properties are a way to simplify the syntax and reduce the amount of code you need to write.

Some good resources for flex-box reference:

https://flexbox.io

CSS Flexbox Layout Guide | CSS-Tricks