Curriculum
Course: CSS Advanced
Login

Curriculum

CSS Advanced

CSS Rounded Corners

0/1

CSS Border Images

0/1

CSS Color Keywords

0/1

CSS Text Effects

0/1

CSS 2D Transforms

0/1

CSS 3D Transforms

0/1

CSS Transitions

0/1

CSS Animations

0/1

CSS Tooltip

0/1

CSS Style Images

0/1

CSS Image Reflection

0/1

CSS Masking

0/1

CSS Buttons

0/1

CSS Multiple Columns

0/1

CSS User Interface

0/1

CSS Box Sizing

0/1

CSS Media Queries

0/1
Text lesson

CSS Flex Items

Child Elements (Items)

The immediate child elements of a flex container are automatically designated as flexible (flex) items.

IMG_3718

The element depicted above showcases four blue flex items contained within a gray flex container.

Example 

<div class=”flex-container”>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>

The properties of flex items include:

  • order
  • flex-grow
  • flex-shrink
  • flex-basis
  • flex
  • align-self

The order Property

The order property determines the sequence of the flex items.

IMG_3719

The initial flex item in the code doesn’t necessarily need to be positioned as the first item in the layout.

The order value must be a numeric value, with the default being 0.

Example 

The order property has the ability to modify the arrangement of the flex items.

<div class=”flex-container”>
  <div style=”order: 3″>1</div>
  <div style=”order: 2″>2</div>
  <div style=”order: 4″>3</div>
  <div style=”order: 1″>4</div>
</div>

The flex-grow Property

The flex-grow property determines the extent to which a flex item can expand compared to other flex items.

IMG_3720

The value must be numeric, with the default being 0.
Example 

Increase the growth rate of the third flex item by eight times compared to the other flex items.

<div class=”flex-container”>
  <div style=”flex-grow: 1″>1</div>
  <div style=”flex-grow: 1″>2</div>
  <div style=”flex-grow: 8″>3</div>
</div>

The flex-shrink Property

The flex-shrink property determines the extent to which a flex item can decrease in size relative to other flex items.

IMG_3721

The value must be numeric, with the default set to 1.

Example 

Restrict the amount of shrinkage for the third flex item compared to the other flex items.

<div class=”flex-container”>
  <div>1</div>
  <div>2</div>
  <div style=”flex-shrink: 0″>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
  <div>7</div>
  <div>8</div>
  <div>9</div>
  <div>10</div>
</div>

The flex-basis Property

The flex-basis property defines the initial size of a flex item.

IMG_3722

Example 

Define the initial size of the third flex item as 200 pixels.

<div class=”flex-container”>
  <div>1</div>
  <div>2</div>
  <div style=”flex-basis: 200px”>3</div>
  <div>4</div>
</div>

The flex Property

The flex property serves as a shorthand for the flex-grow, flex-shrink, and flex-basis properties.

Example 

Ensure that the third flex item cannot grow (0), shrink (0), and set its initial size to 200 pixels.

<div class=”flex-container”>
  <div>1</div>
  <div>2</div>
  <div style=”flex: 0 0 200px”>3</div>
  <div>4</div>
</div>

The align-self Property

The align-self property determines the alignment of the selected item within the flexible container.

It overrides the default alignment established by the container’s align-items property.

IMG_3723

In these examples, we utilize a container with a height of 200 pixels to provide a clearer illustration of the align-self property.

Example 

Position the third flex item at the center of the container.

<div class=”flex-container”>
  <div>1</div>
  <div>2</div>
  <div style=”align-self: center”>3</div>
  <div>4</div>
</div>

 

Example 

Align the second flex item to the top of the container, and the third flex item to the bottom of the container.

<div class=”flex-container”>
  <div>1</div>
  <div style=”align-self: flex-start”>2</div>
  <div style=”align-self: flex-end”>3</div>
  <div>4</div>
</div>