Center the alignments for all the items of the flexible <div> element:
div {
display: flex;
align-items: center;
}
Try it Yourself »
More "Try it Yourself" examples below.
The align-items
property specifies the default alignment for items inside a flexbox or grid container.
For this property to have any alignment effect, the items need available space around themselves in the appropriate direction.
Tip: Use the align-self
property of each item to override the align-items
property.
Default value: | normal |
---|---|
Inherited: | no |
Animatable: | no. Read about animatable |
Version: | CSS3 |
JavaScript syntax: | object.style.alignItems="center" Try it |
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
align-items | 57.0 | 16.0 | 52.0 | 10.1 | 44.0 |
align-items: normal|stretch|
positional alignment|flex-start|flex-end|baseline|initial|inherit;
Value | Description | Play it |
---|---|---|
normal | Default. Behaves like 'stretch' for flexbox and grid items, or 'start' for grid items with a defined block size. | Demo ❯ |
stretch | Items are stretched to fit the container | Demo ❯ |
center | Items are positioned at the center of the container | Demo ❯ |
flex-start | Items are positioned at the beginning of the container | Demo ❯ |
flex-end | Items are positioned at the end of the container | Demo ❯ |
start | Items are positioned at the beginning of their individual grid cells, in the block direction | |
end | Items are positioned at the end of the their individual grid cells, in the block direction | |
baseline | Items are positioned at the baseline of the container | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Items are positioned at the beginning of the container:
div {
display: flex;
align-items: flex-start;
}
Try it Yourself »
Items are positioned at the end of the container:
div {
display: flex;
align-items: flex-end;
}
Try it Yourself »
Items are positioned at the baseline of the container:
div {
display: flex;
align-items: baseline;
}
Try it Yourself »
Items are stretched to fit the container:
div {
display: flex;
align-items: stretch;
}
Try it Yourself »
Items are aligned at the start of each grid cell in the block direction:
#container {
display: grid;
align-items: start;
}
Try it Yourself »
Items are aligned at the end of each grid cell in the block direction for absolute positioned grid items:
#container {
display: grid;
position: relative;
align-items: end;
}
#container > div {
position: absolute;
}
Try it Yourself »
CSS tutorial: CSS grid
CSS tutorial: CSS flexbox
CSS Reference: align-content property
CSS Reference: align-self property
CSS Reference: justify-content property
CSS Reference: justify-items property
CSS Reference: justify-self property
HTML DOM reference: alignItems property
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!