Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Justifying Content Horizontally | Flexbox
CSS Fundamentals

book
Justifying Content Horizontally

The justify-content property is instrumental in determining the position of flex items along the main axis. Its default value is flex-start.

css
justify-content: flex-start | flex-end | center | space-between | space-around;

Let's consider each case on practice. We will play with the list of cards.

flex-start

Default value, which makes all the items be at the start of the main axis.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<ul class="cards-list">
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/joker.png"
alt="Joker"
width="64px"
/>
<p>
The Joker is Batman's iconic supervillain known for his chaotic and
sadistic behavior and disfigured clown appearance.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/alien.png"
alt="Alien"
width="64px"
/>
<p>
An alien is a being from a planet other than Earth, often depicted as
having extraterrestrial features and advanced technology.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/clown.png"
alt="Clown"
width="64px"
/>
<p>

flex-end

All items are at the axis end.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<ul class="cards-list">
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/joker.png"
alt="Joker"
width="64px"
/>
<p>
The Joker is Batman's iconic supervillain known for his chaotic and
sadistic behavior and disfigured clown appearance.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/alien.png"
alt="Alien"
width="64px"
/>
<p>
An alien is a being from a planet other than Earth, often depicted as
having extraterrestrial features and advanced technology.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/clown.png"
alt="Clown"
width="64px"
/>
<p>

center

All items are in the center.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<ul class="cards-list">
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/joker.png"
alt="Joker"
width="64px"
/>
<p>
The Joker is Batman's iconic supervillain known for his chaotic and
sadistic behavior and disfigured clown appearance.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/alien.png"
alt="Alien"
width="64px"
/>
<p>
An alien is a being from a planet other than Earth, often depicted as
having extraterrestrial features and advanced technology.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/clown.png"
alt="Clown"
width="64px"
/>
<p>

space-around

It distributes all the items evenly along the main axis with a bit of space left at either end.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<ul class="cards-list">
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/joker.png"
alt="Joker"
width="64px"
/>
<p>
The Joker is Batman's iconic supervillain known for his chaotic and
sadistic behavior and disfigured clown appearance.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/alien.png"
alt="Alien"
width="64px"
/>
<p>
An alien is a being from a planet other than Earth, often depicted as
having extraterrestrial features and advanced technology.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/clown.png"
alt="Clown"
width="64px"
/>
<p>

space-between

It is very similar to space-around except that it doesn't leave any space at the axis on both ends.

html

index.html

css

index.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<ul class="cards-list">
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/joker.png"
alt="Joker"
width="64px"
/>
<p>
The Joker is Batman's iconic supervillain known for his chaotic and
sadistic behavior and disfigured clown appearance.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/alien.png"
alt="Alien"
width="64px"
/>
<p>
An alien is a being from a planet other than Earth, often depicted as
having extraterrestrial features and advanced technology.
</p>
</li>
<li class="card">
<img
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/clown.png"
alt="Clown"
width="64px"
/>
<p>
question mark

Which of the following values for the justify-content property will align flex items along the center of a flex container?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 3
some-alt