The place-content property
The place-content
property specifies
an alignment of elements along the main and
cross axes for flex elements, and along the
inline and block axes for grids. The first
value indicates alignment along the main
(inline) axis, the second value indicates
the cross (block) axis. The property is
applied to parent element.
Syntax
selector {
place-content: main_axis cross_axis;
}
Example . Alignment to the start of the main and center to the cross axes
Now the elements are pressed to the top of the main axis and at the same time located in the center of the cross one:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
#parent {
display: flex;
place-content: start center;
flex-wrap: wrap;
height: 200px;
border: 1px solid #696989;
}
#parent > div {
width: 100px;
height: 50px;
border: 1px solid #696989;
}
:
Example . Alignment to the center of the main and end of the cross axis
And now the elements are located in the center of the main axis and at the end of the cross:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
#parent {
display: flex;
place-content: center end;
flex-wrap: wrap;
height: 200px;
border: 1px solid #696989;
}
#parent > div {
width: 100px;
height: 50px;
border: 1px solid #696989;
}
:
Example . Alignment to the end of the main and the start of the cross axis
Here the elements are pressed to the bottom of the main axis and at the same time to the start of the cross:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
#parent {
display: flex;
place-content: end start;
flex-wrap: wrap;
height: 200px;
border: 1px solid #696989;
}
#parent > div {
width: 100px;
height: 50px;
border: 1px solid #696989;
}
:
Example . Alignment to the start of the block and end of the inline axes in a grid
Let's align our elements to the start of the block and end of the inline axes:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
#parent {
display: grid;
place-content: start end;
grid-template-columns: 100px 100px;
gap: 10px;
padding: 10px;
border: 2px solid #696989;
height: 200px;
width: 400px;
}
#parent > div {
gap: 10px;
padding: 10px;
box-sizing: border-box;
border: 1px solid #696989;
}
:
Example . Alignment to the center of the block and the start of the inline axes in a grid
Let's align our elements to the center of the block and the start of the inline axes:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
#parent {
display: grid;
place-content: center start;
grid-template-columns: 100px 100px;
gap: 10px;
padding: 10px;
border: 2px solid #696989;
height: 200px;
width: 400px;
}
#parent > div {
gap: 10px;
padding: 10px;
box-sizing: border-box;
border: 1px solid #696989;
}
:
Example . Alignment to the end of the block and the start of the inline axes in a grid
Let's align our elements along the end of the block and the start of the inline axes:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
#parent {
display: grid;
place-content: end start;
grid-template-columns: 100px 100px;
gap: 10px;
padding: 10px;
border: 2px solid #696989;
height: 200px;
width: 400px;
}
#parent > div {
gap: 10px;
padding: 10px;
box-sizing: border-box;
border: 1px solid #696989;
}
:
See also
-
the
align-content
property
that specifies an alignment along the cross or block axis -
the
justify-content
property
that sets an alignment along the main axis