From the course: CSS Essential Training
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Aligning flex items - CSS Tutorial
From the course: CSS Essential Training
Aligning flex items
- [Instructor] Prior to Flexbox, there were options for center-aligning elements horizontally, but getting elements to align vertically required a few hacks. With Flexbox, two new properties were introduced to achieve this effect. The justify-content property aligns the flex items on the main axis. The align-items property aligns flex items on the cross axis. To center-align a flex item vertically and horizontally, set the value to center for both properties, and that's it. No workarounds required. But these two properties can do a lot more than just center-align items. They can also be used to distribute space between and around the items. Let's look at a demo in CodePen. Right now, we have three list items contained in an unordered list. They're block items, so by default, they stack on top of each other and are the same width as the container. Let's add display flex to initiate the flex layout and define the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
Intro to Grid and Flexbox59s
-
(Locked)
Intro to Flexbox2m 25s
-
(Locked)
Flexbox: Orientation and ordering3m 1s
-
(Locked)
Sizing with flex properties2m 29s
-
(Locked)
Flexbox exercise3m 51s
-
(Locked)
Project: Sticky footer with flexbox5m 39s
-
(Locked)
Aligning flex items3m 20s
-
(Locked)
Project: Aligning elements with Flexbox3m 41s
-
(Locked)
Intro to CSS Grid2m 23s
-
(Locked)
The explicit grid3m 59s
-
(Locked)
The implicit grid2m 58s
-
(Locked)
Adding gutters with the gap property1m 21s
-
(Locked)
Project: Adding columns with Grid8m 15s
-
-
-
-