YouTip LogoYouTip

Css3 Pr Justify Content

CSS justify-content Property | \n \n \n body { font-family: Arial, sans-serif; line-height: 1.6; margin: 20px; }\n h1 { color: #333; }\n h2 { color: #444; border-bottom: 1px solid #eee; padding-bottom: 5px; }\n .example { background: #f9f9f9; border: 1px solid #ddd; padding: 15px; margin: 10px 0; border-radius: 5px; }\n .note { background: #fff3cd; border: 1px solid #ffeeba; padding: 10px; margin: 10px 0; border-radius: 5px; }\n table { border-collapse: collapse; width: 100%; margin: 10px 0; }\n th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }\n th { background-color: #f2f2f2; }\n code { background-color: #f1f1f1; padding: 2px 4px; border-radius: 3px; font-family: monospace; }\n pre { background-color: #f1f1f1; padding: 10px; border-radius: 5px; overflow-x: auto; }\n \n\n

CSS justify-content Property

\n\n

Definition and Usage

\n

justify-content property is used to set the alignment of items within the container along the main axis in a flexbox layout.

\n\n

Syntax

justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly | initial | inherit;

Property Values

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
ValueDescription
flex-startDefault. Items are placed at the beginning of the container.
flex-endThe item is located at the end of the container.
centerThe item is centered in the container.
space-betweenItems have equal space between them. The first item is at the start line, and the last item is at the end line.
space-aroundThe spacing on both sides of each item is equal. Note that the spacing between adjacent items is twice the spacing between the item and the edge.
space-evenlyThe spacing between items (including between items and edges) is exactly equal.
initialSet this property to its default value.
inheritInherits this property from its parent element.
\n\n
\n Note: This property is only effective in Flexbox layout (when\n
display: flex or display: inline-flextime).\n
\n\n

Examples

\n\n

1. justify-content: flex-start (default)

\n
\n

Items are placed at the start of the container.

.container {\n  display: flex;\n  justify-content: flex-start;\n}
\n\n

2. justify-content: flex-end

\n
\n

Items are aligned at the end of the container.

.container {\n  display: flex;\n  justify-content: flex-end;\n}
\n\n

3. justify-content: center

\n
\n

Items are positioned at the center of the container.

.container {\n  display: flex;\n  justify-content: center;\n}
\n\n

4. justify-content: space-between

\n
\n

Equal spacing is distributed between items. The first item is on the start line, and the last item is on the end line.

.container {\n  display: flex;\n  justify-content: space-between;\n}
\n\n

5. justify-content: space-around

\n
\n

The spacing on both sides of each item is equal. Note that the spacing between adjacent items is twice the spacing between an item and the edge.

.container {\n  display: flex;\n  justify-content: space-around;\n}
\n\n

6. justify-content: space-evenly

\n
\n

The spacing between items (including between items and edges) is completely equal.

.container {\n  display: flex;\n  justify-content: space-evenly;\n}
\n\n

Browser Support

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
AttributeChromeEdgeFirefoxSafariOpera
justify-content29.0+12.0+28.0+9.0+17.0+
\n\n

\n
← Css3 Pr OrderCss3 Pr Animation Fill Mode β†’