The align-items:center; property will vertically position the flex-items at the center of the container. The following example shows the result of using the strong>center value:
HTML file: | Displayed by browser: |
---|---|
<style>
.flex-container { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; width: 400px; height: 250px; background-color: lightgrey; } .flex-item { background-color: cornflowerblue; width: 100px; /* NOTICE THERE IS NO HEIGHT*/ margin: 10px; } </style> <body> <div class="flex-container"> <div class="flex-item">flex item 1</div> <div class="flex-item">flex item 2</div> <div class="flex-item">flex item 3</div> </div> </body> |
flex item 1
flex item 2
flex item 3
|
Items are aligned to the center of the flex-container.