JavaScript 参考手册
Style alignItems 属性
居中对齐灵活的 <div> 元素的各项
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <style> div#main { 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 with more content.</div> </div> <p>点击“尝试一下”按钮设置 alignItems 属性的值为 "flex-start"。</p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { document.getElementById("main").style.alignItems = "flex-start"; } </script> <p><b>注意:</b>Safari 不支持 alignItems 属性。</p> </body> </html>
运行结果:
点击运行 »