HTML CSS examples for CSS Property:justify-content
The justify-content CSS property sets how flex items are aligned along the main axis of the flex container.
The following table summarizes the justify-content Property.
Item | Value |
---|---|
Default value: | flex-start |
Applies to: | Flex containers |
Inherited: | No |
Animatable: | No. |
The syntax of the property is as follows:
justify-content: flex-start | flex-end | center | space-between | space-around | initial | inherit
The following table describes the values of this property.
Value | Description |
---|---|
flex-start | packed toward the start of the line. This is default value. |
flex-end | packed toward the end of the line. |
center | packed toward the center of the line. |
space-between | evenly distributed along the line. |
space-around | evenly distributed so that the space between two adjacent items is the same. |
initial | Sets this property to its default value. |
inherit | take the value of its parent element justify-content property. |
The example below shows the justify-content property.
<!DOCTYPE html> <html lang="en"> <head> <title>Example of CSS3 justify-content Property</title> <style type="text/css"> .flex-container {<!-- ww w.j av a 2 s. c om--> height: 200px; width: 300px; font-size: 32px; border: 1px solid black; /* Safari */ display: -webkit-flex; -webkit-justify-content: space-around; /* Standard syntax */ display: flex; justify-content: space-around; } .flex-container div { width: 75px; } .item1 { background: #e84d51; } .item2 { background: #7ed636; } .item3 { background: #2f97ff; } </style> </head> <body> <div class="flex-container"> <div class="item1"> 1 </div> <div class="item2"> 2 </div> <div class="item3"> 3 </div> </div> </body> </html>