Javascript examples for CSS Style Property:alignItems
The alignItems property sets the default alignment for elements inside the flexible container.
Value | Description |
---|---|
stretch | Default. Items are 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. |
Item | Value |
---|---|
Default Value: | stretch |
Return Value: | A String, representing the align-items property of an element |
CSS Version | CSS3 |
The following code shows how to Position the alignments for all the items of the flexible <div> element at the beginning of the container:
<!DOCTYPE html> <html> <head> <style> div#main {//www . j a v a 2s .c o m width: 200px; height: 300px; border: 1px solid black; display: -webkit-flex; /* Safari */ -webkit-align-items: center; /* Safari 7.0+ */ display: flex; align-items: center; } div#main div { -webkit-flex: 1; /* Safari 7.0+ */ 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 with more content.</div> </div> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("main").style.WebkitAlignItems = "flex-start"; // Code for Safari 7.0+ document.getElementById("main").style.alignItems = "flex-start"; } </script> </body> </html>