菜单切换
FACESOHO知行者
心灵
记录
远方
赞赏工具
源代码:
点击运行
保存
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>小鸟启蒙(facesoho.com)</title> <style> #main{ width:220px; height:300px; border:1px solid black; display:flex; align-items:flex-start; } #main div{ flex:1; } #myBlueDiv{ 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> <p>点击“尝试一下”按钮设置 alignSelf 属性的值为 "stretch"。</p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction(){ document.getElementById("myBlueDiv").style.alignSelf = "stretch"; } </script> <p><b>注意:</b>Internet Explorer 和 Safari 不支持 alignSelf 属性。</p> </body> </html>
运行结果