CSS CSS Tutorial CSS Advanced CSS Responsive Web Design(RWD) CSS Grid CSS Properties Sass Tutorial Sass Functions



align-content

CSS align-content property is used to align the content inside a flex container when there is extra space in the cross-axis. It is used to distribute the extra space between the rows or columns of a multi-line flex container. The align-content property is used in conjunction with the flex-wrap property, which specifies whether the flex items should wrap or not.

The align-content property has several possible values:

  • flex-start: aligns the content to the start of the container.
  • flex-end: aligns the content to the end of the container.
  • center: aligns the content to the center of the container.
  • space-between: distributes the content evenly between the rows or columns.
  • space-around: distributes the content evenly with equal space around each row or column.
  • stretch: stretches the content to fill the container.

Let's take a look at some code examples:

Example 1: flex-start

In this example, the content is aligned to the start of the container:


.container {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
}

Example 2: flex-end

In this example, the content is aligned to the end of the container:


.container {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-end;
}

Example 3: center

In this example, the content is aligned to the center of the container:


.container {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
}

Example 4: space-between

In this example, the content is distributed evenly between the rows or columns:


.container {
  display: flex;
  flex-wrap: wrap;
  align-content: space-between;
}

Example 5: space-around

In this example, the content is distributed evenly with equal space around each row or column:


.container {
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
}

Example 6: stretch

In this example, the content is stretched to fill the container:


.container {
  display: flex;
  flex-wrap: wrap;
  align-content: stretch;
}

These are just a few examples of how the align-content property can be used. It is a powerful tool for aligning content inside a flex container and can be used in a variety of ways to achieve different layouts.

Conclusion

The align-content property is a useful tool for aligning content inside a flex container. It can be used in conjunction with the flex-wrap property to create multi-line flex containers and distribute the extra space between the rows or columns. By using the different values of the align-content property, you can achieve a variety of layouts and designs.

References

Activity