CSS3: Align the flex-items at center

This entry is part 9 of 13 in the series CSS3

Using a single line of justify-content: center will position the Flex Items at the center along the Main axis.

<!DOCTYPE html>
<head lang='en'>
    <meta charset='UTF-8'>
        #flex-container {
            display: -webkit-flex;
            display: flex;
            width: 500px;
            height: 500px;
            background-color: gray;
            justify-content: center;

        #flex-item {
            background-color: Silver;
            width: 200px;
            height: 200px;
            margin: 10px;
<div id='flex-container'>
    <div id='flex-item'>I am content block A</div>
    <div id='flex-item'><img src='http://codecrawl.com/code/images/ushuaia.jpg' alt='Ushuaia' width='200px' height='200px'/></div>

The other values that can use to align the items at main axis are:

Series Navigation<< CSS3: Flexbox and image alignment
CSS3: Align flex-items along cross axis >>

Leave a comment

Leave a Reply