Edit This Code:
See Result »
<!DOCTYPE html> <html> <head> <style> div#main { width: 220px; 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> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?73c27e26f610eb3c9f3feb0c75b03925"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </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> <p>Click the "Try it" button to set the value of the alignItems property to "flex-start"</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { document.getElementById("main").style.WebkitAlignItems = "flex-start"; // Code for Safari 7.0+ document.getElementById("main").style.alignItems = "flex-start"; } </script> <p><b>Note:</b> Internet Explorer 10 and earlier versions do not support the alignItems property.</p> <p><b>Note:</b> Safari 7.0 (and newer) supports an alternative, the WebkitAlignItems property.</p> </body> </html>
Result: