运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> #main { width: 250px; height: 100px; border: 1px solid #c3c3c3; display: flex; } #main div { flex: 0 0 50px; } </style> </head> <body> <h1>Change flex with JavaScript</h1> <div id="main"> <div style="background-color:coral;">Red DIV</div> <div style="background-color:lightblue;" id="myBlueDiv">Blue DIV</div> </div> <p>Click the "Try it" button to set the value of the flex property to "200px" for the blue div element</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { document.getElementById("myBlueDiv").style.flex = "0 0 200px"; } </script> </body> </html>