Skip to main content

--description--

The align-items property is similar to justify-content. Recall that the justify-content property aligned flex items along the main axis. For rows, the main axis is a horizontal line and for columns it is a vertical line.

Flex containers also have a cross axis which is the opposite of the main axis. For rows, the cross axis is vertical and for columns, the cross axis is horizontal.

CSS offers the align-items property to align flex items along the cross axis. For a row, it tells CSS how to push the items in the entire row up or down within the container. And for a column, how to push all the items left or right within the container.

The different values available for align-items include:

  • flex-start: aligns items to the start of the flex container. For rows, this aligns items to the top of the container. For columns, this aligns items to the left of the container.
  • flex-end: aligns items to the end of the flex container. For rows, this aligns items to the bottom of the container. For columns, this aligns items to the right of the container.
  • center: align items to the center. For rows, this vertically aligns items (equal space above and below the items). For columns, this horizontally aligns them (equal space to the left and right of the items).
  • stretch: stretch the items to fill the flex container. For example, rows items are stretched to fill the flex container top-to-bottom. This is the default value if no align-items value is specified.
  • baseline: align items to their baselines. Baseline is a text concept, think of it as the line that the letters sit on.

--instructions--

An example helps show this property in action. Add the CSS property align-items to the #box-container element, and give it a value of center.

Bonus
Try the other options for the align-items property in the code editor to see their differences. But note that a value of center is the only one that will pass this challenge.

--hints--

The #box-container element should have an align-items property set to a value of center.

assert($('#box-container').css('align-items') == 'center');

--seed--

--seed-contents--

<style>
#box-container {
background: gray;
display: flex;
height: 500px;

}
#box-1 {
background-color: dodgerblue;
width: 200px;
font-size: 24px;
}

#box-2 {
background-color: orangered;
width: 200px;
font-size: 18px;
}
</style>

<div id="box-container">
<div id="box-1"><p>Hello</p></div>
<div id="box-2"><p>Goodbye</p></div>
</div>

--solutions--

<style>
#box-container {
background: gray;
display: flex;
height: 500px;
align-items: center;
}
#box-1 {
background-color: dodgerblue;
width: 200px;
font-size: 24px;
}

#box-2 {
background-color: orangered;
width: 200px;
font-size: 18px;
}
</style>

<div id="box-container">
<div id="box-1"><p>Hello</p></div>
<div id="box-2"><p>Goodbye</p></div>
</div>