CSS
Optimizing Layouts with CSS Justify-content Flex-start to Space-evenly
- justify-content: flex-start
- justify-content: flex-end
- justify-content: center
- justify-content: space-around
- justify-content: space-evenly
The justify-content
property is used in the context of Flexbox, which is a layout model in CSS. It is applied to the parent container of a set of flex items and determines how the items are distributed along the main axis. Here are examples of how different values of justify-content
affect the layout:
¶justify-content: flex-start
This aligns the flex items to the start of the container.
<div style="display: flex; justify-content: flex-start; border: 1px solid #ccc;">
<div style="width: 50px; height: 50px; background-color: red;"></div>
<div style="width: 50px; height: 50px; background-color: green;"></div>
<div style="width: 50px; height: 50px; background-color: blue;"></div>
</div>
¶Output:
¶justify-content: flex-end
This aligns the flex items to the end of the container.
<div style="display: flex; justify-content: flex-end; border: 1px solid #ccc;">
<div style="width: 50px; height: 50px; background-color: red;"></div>
<div style="width: 50px; height: 50px; background-color: green;"></div>
<div style="width: 50px; height: 50px; background-color: blue;"></div>
</div>
¶Output:
¶justify-content: center
This centers the flex items along the main axis.
<div style="display: flex; justify-content: center; border: 1px solid #ccc;">
<div style="width: 50px; height: 50px; background-color: red;"></div>
<div style="width: 50px; height: 50px; background-color: green;"></div>
<div style="width: 50px; height: 50px; background-color: blue;"></div>
</div>
¶Output:
¶justify-content: space-between
This evenly distributes the flex items along the main axis, with the first item at the start and the last item at the end.
<div style="display: flex; justify-content: space-between; border: 1px solid #ccc;">
<div style="width: 50px; height: 50px; background-color: red;"></div>
<div style="width: 50px; height: 50px; background-color: green;"></div>
<div style="width: 50px; height: 50px; background-color: blue;"></div>
</div>
¶Output:
¶justify-content: space-around
This evenly distributes the flex items along the main axis, with equal space around them.
<div style="display: flex; justify-content: space-around; border: 1px solid #ccc;">
<div style="width: 50px; height: 50px; background-color: red;"></div>
<div style="width: 50px; height: 50px; background-color: green;"></div>
<div style="width: 50px; height: 50px; background-color: blue;"></div>
</div>
¶Output:
¶justify-content: space-evenly
This evenly distributes the flex items along the main axis with equal space around them.
<div style="display: flex; justify-content: space-evenly; border: 1px solid #ccc;">
<div style="width: 50px; height: 50px; background-color: red;"></div>
<div style="width: 50px; height: 50px; background-color: green;"></div>
<div style="width: 50px; height: 50px; background-color: blue;"></div>
</div>
¶Output:
These examples illustrate how different justify-content values affect the layout of flex items within a container. You can experiment with these values and adjust the styles to see the changes in the layout.
Fine-Tuning Flex-shrink and Flex-basis for Responsive CSS Layouts
Mastering CSS Align-items and Align-self for Seamless Layouts
All Tutorials in this playlist
Popular Tutorials
Categories
-
Artificial Intelligence (AI)
11
-
Bash Scripting
1
-
Bootstrap CSS
0
-
C Programming
14
-
C#
0
-
ChatGPT
1
-
Code Editor
2
-
Computer Engineering
3
-
CSS
28
-
Data Structure and Algorithm
18
-
Design Pattern in PHP
2
-
Design Patterns - Clean Code
1
-
E-Book
1
-
Git Commands
1
-
HTML
19
-
Interview Prepration
2
-
Java Programming
0
-
JavaScript
12
-
Laravel PHP Framework
37
-
Mysql
1
-
Node JS
1
-
Online Business
0
-
PHP
28
-
Programming
8
-
Python
12
-
React Js
19
-
React Native
1
-
Redux
2
-
Rust Programming
15
-
SEO - Search Engine Optimization
1
-
Tailwind CSS
1
-
Typescript
10
-
Uncategorized
0
-
Vue JS
1
-
Windows Operating system
1
-
Woocommerce
1
-
WordPress Development
2
Tags
- Artificial Intelligence (AI)
- Bash Scripting
- Business
- C
- C Programming
- C-sharp programming
- C++
- Code Editor
- Computer Engineering
- CSS
- Data Structure and Algorithm
- Database
- Design pattern
- Express JS
- git
- Git Commands
- github
- HTML
- Java
- JavaScript
- Laravel
- Mathematics
- MongoDB
- Mysql
- Node JS
- PHP
- Programming
- Python
- React Js
- Redux
- Rust Programming Language
- SEO
- TypeScript
- Vue JS
- Windows terminal
- Woocommerce
- WordPress
- WordPress Plugin Development