CSS Property: align-self
[this page | pdf | back links]
The CSS (CSS3) align-self property specifies the
alignment for the selected item within a flexible container. Use the align-items
property to set the default that otherwise applies to the items in the flexible
container.
Valid property values
(other than inherit
and initial) are:
Value
|
Description
|
auto
|
(default value). Element
inherits its parent container’s align-items property, or "stretch"
if it has no parent container
|
baseline
|
Items positioned at
baseline of container
|
center
|
Items positioned at centre
of container
|
flex-end
|
Items positioned at end
of container
|
flex-start
|
Items positioned at
start of container
|
stretch
|
Items stretched to fit
container
|
Default Value:
|
auto
|
JavaScript syntax:
|
e.g. object.style.alignSelf = "center";
|
Inherited:
|
No
|
Animatable:
|
No
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
.x1 {align-self: flex-end;}
</style>
</head>
<body>
1. Element with default property<br>
<div style="display: flex; width: 200px; height: 60px; border: 2px solid red;">
<div>text 1</div><div>text 2</div><div>text 3</div>
</div>
<br>
2. Element set using in-file HTML style<br>
<div style="display: flex; width: 200px; height: 60px; border: 2px solid red;">
<div>text 1</div><div>text 2</div><div class="x1">text 3</div>
</div>
<br>
3. Element set using JavaScript<br>
<div style="display: flex; width: 200px; height: 60px; border: 2px solid red;">
<div>text 1</div><div>text 2</div><div id="x2">text 3</div>
</div>
<br>
<script>
document.getElementById("x2").style.alignSelf = "flex-end";
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyAlignSelf() {
var x = document.createElement("DIV"); x.style.alignSelf = "center"; return (window.getComputedStyle(x, null).alignSelf == "center");
} |
NAVIGATION LINKS
Contents | Prev | Next | CSS Properties