CSS Introduction

CSS Tutorial What is CSS CSS Syntax CSS Selector How to include CSS CSS Comments

CSS Attributes

CSS Background CSS Border CSS Display CSS Float CSS Font CSS Color CSS Hover CSS Important CSS Line-height CSS Margin CSS Opacity CSS Filter CSS Images CSS Overflow CSS Padding CSS Position CSS Vertical align CSS White space CSS Width Word-wrap in CSS Box-shadow in CSS Text-transform in CSS CSS Outline CSS Visibility CSS Counters CSS Clear fix CSS Icons CSS Justify-content Text-decoration in CSS CSS Lists CSS nth selector CSS Sticky CSS Background-clip CSS Checkbox-style CSS Letter-spacing CSS Navigation bar CSS Overlay CSS Root CSS Specificity CSS Text-indent CSS Text-stroke CSS Zoom CSS Order CSS Descendent selector CSS Clip CSS calc() CSS Background-blend-mode CSS radio-button CSS Superscript and subscript CSS Text-effects CSS Text-align CSS Variables CSS Page-break-before CSS Page-break-inside CSS Page-break-after CSS Content property CSS Word-spacing CSS Animation CSS @keyframes rules CSS Pseudo-classes CSS Pseudo-elements CSS Radial-gradient CSS Translate CSS Gradients CSS z-index CSS Loaders CSS Units CSS Transition CSS Masking CSS Arrow CSS Pagination

Misc

What is Bootstrap CSS What is CSS used for Difference between HTML and CSS How to center a table in CSS What is a CSS File How to center a button in CSS How to change background color in CSS How to change the font in CSS How to change font size in CSS How to resize an image in CSS How to get rid of bullet pioints in CSS Is CSS a programming language Grid Vs Flexbox in CSS How to edit CSS in WordPress How to use google fonts in CSS

CSS Justify Content

Justify Content: These properties are applied for the alignment of items of a flexible box container if any item does not cover every available space over the main-axis, i.e., horizontally. Justify content property specifies how a browser classifies the area everywhere and between any content item.

It is not used to define items or containers inside any vertical axis. We can apply the property, i.e., align-items, for the alignment of the items vertically.

Syntax:

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

The flex-start value is used as a default value. Take a look at the following description:

ValuesDescription
centerAs the name suggests, it set-up an item’s position in the starting of a container.
flex-startIt is used as a default value and places an item at the starting of a container.
flex-endThis value is applied to set an item’s position at a container’s end.
space-aroundThese are applied to position any item along with parallel spacing to each other. The space-around value evenly classifies several items inside the line with the same space about them.
space-betweenBy using this value, an item is spaced evenly. Here, any first item (element) is at a starting, and any last item (element) is at an end.
space-evenlyIt places the items along with a parallel space. Although, the spacing about all the corners varies.

Take a look on the following illustration of these property values:

Example:

<!DOCTYPE html>  
<html>          
<head>  
<title>Justify Content in CSS </title>  
<style>    
#flexstart
{ 
 display: flex; 
 justify-content: flex-start; 
} 
#flexend
{ 
 display: flex; 
 justify-content: flex-end; 
}   
#cent
{ 
 display: flex; 
 justify-content: center; 
} 
#evenly
{ 
 display: flex; 
 justify-content: space-evenly; 
} 
#around
{ 
 display: flex; 
 justify-content: space-around; 
} 
#between
{ 
 display: flex; 
 justify-content: space-between; 
} 
.flex-item
{ 
 width: 50px; 
 height: 50px; 
 margin: 5px; 
 padding: 5px; 
 color: black; 
 font-size: 2em; 
 font-weight: bold; 
 text-align: center; 
 border: 1px solid black; 
 background-color: lightblue; 
} 
</style>  
</head>  
<body>
<div id="flexstart"> 
<h1>flex-start</h1> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
<div id="flexend"> 
<h1>flex-end</h1> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
<div id="cent"> 
<h1>center</h1> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div>  
</div> 
<h1>space-evenly</h1> 
<div id="evenly"> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
<h1>space-around</h1> 
<div id="around"> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
<h1>space-between</h1> 
<div id="between"> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
</body>  
</html> 

Output:

Justify Content



ADVERTISEMENT
ADVERTISEMENT