Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Flexbox Basics | Layouts
Introduction to CSS Part II
course content

Course Content

Introduction to CSS Part II

Flexbox Basics

Flexbox is a layout mode in CSS that makes it easier to create responsive and flexible layouts. It allows elements within a container to be aligned, distributed and stretched more intuitively.

Setting up a flex container

To create a flex container, you need to set the display property of an element to flex or inline-flex. They allow you to specify how elements should be aligned along the main and cross axes and how they should distribute remaining space or shrink to fit the available space.
For example:

When this property is applied to the container element, we can use multiple flexbox-related properties on the element and the child elements. Following are some of the basic properties that are used quite often:

Flex-direction

The flex-direction property determines the direction in which the flex items are laid out. The default value is row, which means the flex items are laid out in a row from left to right. You can also set it to column, which means the flex items are laid out in a column from top to bottom.
For example

The following are other values that may be applied:
row-reverse: Elements are arranged horizontally, from right to left.
column-reverse: Elements are arranged vertically, from bottom to top.

Flex-wrap

The flex-wrap property determines whether the flex items should wrap to the next line when they reach the end of the container. The default value is nowrap, which means the flex items will not wrap. You can set it to wrap, which means the flex items will wrap to the next line when they reach the end of the container.

You can also set the value to wrap-reverse, in which elements are allowed to wrap onto multiple lines in the opposite direction.

1. What is the purpose of the `display` property in CSS?
2. How can you create a flex container in CSS using the `display` property?

What is the purpose of the display property in CSS?

Select the correct answer

How can you create a flex container in CSS using the display property?

Select the correct answer

Everything was clear?

Section 3. Chapter 4
We're sorry to hear that something went wrong. What happened?
some-alt