The alignSelf
property gets and sets the alignment for
the selected item inside the flexible container.
alignSelf |
Yes | 11 | Yes | No | Yes |
Return the alignSelf property:
var v = object.style.alignSelf;
Set the alignSelf property:
object.style.alignSelf='auto|stretch|center|flex-start|flex-end|baseline|initial|inherit'
Default Value: | auto |
---|---|
Return Value: | A string representing the align-self property |
CSS Version | CSS3 |
The following code shows how to center the one of the items inside a flexible element.
<!DOCTYPE html>
<html>
<head>
<style>
#main {<!--from w ww .j av a2 s.c o m-->
width: 220px;
height: 300px;
border: 1px solid black;
display: flex;
align-items: flex-start;
}
#main div {
flex: 1;
}
#myBlueDiv {
align-self: center;
}
</style>
</head>
<body>
<div id="main">
<div style="background-color:red;">RED</div>
<div style="background-color:blue;" id="myBlueDiv">BLUE</div>
<div style="background-color:green;">Green.</div>
</div>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myBlueDiv").style.alignSelf = "stretch";
}
</script>
</body>
</html>
The code above is rendered as follows: