The alignItems property specifies the default alignment for items inside the flexible container.
Position the alignments for all the items of the flexible <div> element at the beginning of the container:
document.getElementById("main").style.alignItems = "flex-start";
Click the button to set the value of the alignItems property to "flex-start".
<!DOCTYPE html> <html> <head> <style> div#main {//from w ww . j av a2 s. c o m width: 220px; height: 300px; border: 1px solid black; display: flex; align-items: center; } div#main div { flex: 1; } </style> </head> <body> <div id="main"> <div style="background-color:coral;">RED</div> <div style="background-color:lightblue;">BLUE</div> <div style="background-color:lightgreen;">Green.</div> </div> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("main").style.alignItems = "flex-start"; } </script> </body> </html>
Property Values
Value | Description |
---|---|
stretch | Default . stretched to fit the container |
center | positioned at the center of the container |
flex-start | positioned at the beginning of the container |
flex-end | positioned at the end of the container |
baseline | positioned at the baseline of the container |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The alignItems property returns a String representing the align-items property of an element.