Align an individual grid item at the end in the block and inline directions:
#myDiv {
place-self: end;
}
Try it Yourself »
More "Try it Yourself" examples below.
The place-self
property is used to align individual grid items, and is a shorthand property for the following properties:
If the place-self property has two values:
If the place-self property has one value:
Default value: | auto |
---|---|
Inherited: | no |
Animatable: | no. Read about animatable |
Version: | CSS3 |
JavaScript syntax: | object.style.placeSelf="end stretch" Try it |
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
place-self | 59.0 | 79.0 | 45.0 | 11.0 | 46.0 |
place-self: auto|
value|initial|inherit;
Value | Description | Demo |
---|---|---|
auto | Default. The element's default place-self value. | Demo ❯ |
normal | Dependant on layout context, but similar to 'stretch' for grid layout for grid items when size is not set. If size is set, the property value behaves lik 'start'. | Demo ❯ |
stretch | Stretches to fill the grid cell if size is not set. | Demo ❯ |
start | Align items at the start in the inline and block directions | Demo ❯ |
left | Align items to the left in the inline direction, as the justify-self property value. | Demo ❯ |
center | Align items to the center | Demo ❯ |
end | Align items at the end in the inline and block directions | Demo ❯ |
right | Align items to the right in the inline direction, as the justify-self property value. | Demo ❯ |
overflow-alignment |
|
|
baseline alignment | The element is aligned with the baseline of the parent. | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
With the writing-mode
property value of a <div> element set to 'vertical-rl', the end of the grid cell in block direction is moved from bottom to the left, and the end of the grid cell in the inline direction is moved from right to the bottom:
#contianer {
display: grid;
writing-mode: vertical-rl;
}
#myDiv {
place-self: end;
}
Try it Yourself »
The place-self
property can also be used for flexbox items, but the second value for justify-self
will be ignored because it is not applicable with flexbox:
#contianer {
display: flex;
}
#myDiv {
place-self: end stretch;
}
Try it Yourself »
CSS tutorial: CSS grid
CSS tutorial: CSS flexbox
CSS align-self property: CSS align-self property
CSS jusitfy-self property: CSS justify-self property
CSS writing-mode property: CSS Writing-mode property
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!