Javascript examples for CSS Style Property:alignSelf
The alignSelf property sets the alignment for an element inside the flexible container.
The alignSelf property overrides the flexible container's alignItems property.
Value | Description |
---|---|
auto | Default. The element inherits its parent container's align-items property, or "stretch" if it has no parent container |
stretch | positioned to fit the container |
center | positioned at the center |
flex-start | are positioned at the beginning |
flex-end | positioned at the end |
baseline | positioned at the baseline |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
A String, representing the align-self property of an element
The following code shows how to set the alignments for one of the items inside a flexible element to fit the container:
<!DOCTYPE html> <html> <head> <style> #main {//from w w w . j a va 2 s .c o m width: 200px; height: 300px; border: 1px solid black; display: -webkit-flex; /* Safari */ -webkit-align-items: flex-start; /* Safari 7.0+ */ display: flex; align-items: flex-start; } #main div { -webkit-flex: 1; /* Safari 6.1+ */ flex: 1; } #myBlueDiv { -webkit-align-self: center; /* Safari 7.0+ */ align-self: center; } </style> </head> <body> <div id="main"> <div style="background-color:coral;">RED</div> <div style="background-color:lightblue;" id="myBlueDiv">BLUE</div> <div style="background-color:lightgreen;">Green div with more content.</div> </div> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("myBlueDiv").style.WebkitAlignSelf = "stretch"; // Code for Safari 7.0+ document.getElementById("myBlueDiv").style.alignSelf = "stretch"; } </script> </body> </html>