CSS justify content
Created By: chatGPT
CSS provides a powerful way to control the layout of your web page through the use of the Flexbox model. One of the key features of Flexbox is the
justify-content
property, which aligns flex items along the main axis of their container. This can help create a visually appealing design by organizing elements within a flex container effectively. Here are the main values you can use with justify-content
:flex-start: Aligns items to the start of the container.
.container {
display: flex;
justify-content: flex-start;
}
flex-end: Aligns items to the end of the container.
.container {
display: flex;
justify-content: flex-end;
}
center: Centers items in the container.
.container {
display: flex;
justify-content: center;
}
space-between: Distributes items evenly, with the first item at the start and the last item at the end.
.container {
display: flex;
justify-content: space-between;
}
space-around: Distributes items evenly with equal space around them.
.container {
display: flex;
justify-content: space-around;
}
space-evenly: Distributes items evenly with equal space between them, including the ends.
.container {
display: flex;
justify-content: space-evenly;
}
Here’s a simple example demonstrating the different
justify-content
values:<div class='container'>
<div class='item'>Item 1</div>
<div class='item'>Item 2</div>
<div class='item'>Item 3</div>
</div>
<style>
.container {
display: flex;
justify-content: space-between; /* Try changing this value */
}
.item {
background: lightgray;
margin: 5px;
padding: 20px;
}
</style>