Overview
The align-items property is used to vertically align the flex items within the flex container.
Note
The following are basic examples. Towards the bottom of this page you’ll find a complete list of all applicable properties, where you can find more information on the properties discussed, and sometimes find more involved properties not discussed on this page.
Vertically Aligning the Content
<div class="flex_container">
<div>Box 1</div>
<div>Box 2</div>
<div>Box 3</div>
</div>
Line 5 below sets the type.
.flex_container {
display: flex;
background-color: #ffbd02;
flex-direction: row;
align-items: flex-start;
}
.flex_container > div {
background-color: #eaeaea;
margin: 10px;
padding: 20px;
font-size: 22px;
}
align-items: flex-start;
align-items: flex-end;
align-items: center;
align-items: stretch; (default)
align-items: baseline;
For this one, the size of the text is different for each element to show that the boxes are being vertically aligned by the baseline of the text.
Flex Properties
- CSS – align-content PropertyThe align-content property modifies the behavior of the flex-wrap property by aligning multiple flex lines along the vertical axis.
- CSS – align-items PropertyThe align-items property specifies the vertical alignment for items inside the flex container. The following has three divs aligned centered on the horizontal axis.
- CSS – align-self PropertyThe align-self property specifies the alignment for the specific item inside a flexible container.
- CSS – flex PropertyThe flex property is a shorthand property for: flex-basis, flex-grow, and flex-shrink.
- CSS – flex-basis PropertyThe flex-basis property specifies the initial length of a flexible item.
- CSS – flex-direction PropertyThe flex-direction property specifies the direction of the flexible items.
- CSS – flex-flow PropertyThe flex-flow property is a shorthand property for flex-direction and flex-wrap.
- CSS – flex-grow PropertyThe flex-grow property specifies how much the item will grow relative to the rest of the flexible itemsinside the same container.
- CSS – flex-shrink PropertyThe flex-shrink property specifies how the item will shrink relative to the rest of the flexible items inside the same container.
- CSS – flex-wrap PropertyThe flex-wrap property specifies whether the flexible item should wrap or not.
- CSS – justify-content PropertyThe justify-content property aligns the flexible container’s items when the items do not use all available space on the horizontal axis.
- CSS – order PropertyThe order property specifies the order of a flexible item relative to the rest of the flexible items inside the same container.
CSS Notes:
- The “inherit”, “initial” and “unset” keywords can be used with any CSS property to set its value
- In CSS there are many ways to express a color value in a property
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.