已关闭,该问题需要details or clarity,目前不接受回答。**想要改进此问题?**通过editing this post添加详细信息并澄清问题。
2天前关闭。Improve this question
我试过使用div,但不好
wd2eg0qa1#
这是你应该使用网格的东西,但是用flex也可以做到这一点,你只需要很多额外的容器div。
.main { width: 100vw; height: 100vh; background: lightgray; display: flex; } .dividerbox-vertical { width: 70%; display: flex; flex-direction: column; } .dividerbox-horizontal { width: 100%; height: 50%; display: flex; flex-direction: row; } .one { width: 30%; height: 100%; background: red; } .two { width: 100%; height: 50%; background: green; } .three { width: 50%; height: 100%; background: pink; } .four-a { width: 100%; height: 50%; background: lightblue; } .four-b { width: 100%; height: 50%; background: blue; }
<div class="main"> <div class="one"></div> <div class="dividerbox-vertical"> <div class="two"></div> <div class="dividerbox-horizontal"> <div class="three"></div> <div class="dividerbox-vertical"> <div class="four-a"></div> <div class="four-b"></div> </div> </div> </div> </div>
0kjbasz62#
如果你想要纯粹的flexbox风格,
body{ padding: 0; margin: 0; color: white; font-size: 50px; text-align: center; font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; } .container{ background-color: #9b9b9b; height: 60vh; padding: 15px; display: flex; flex-direction: row; width: 60vw; position: absolute; top: 50%; left: 50%; transform:translate(-50%, -50%) } .box1{ background-color: #ff7676; padding: 10px; margin: 10px; width: 30vw; } .box2{ display: flex; flex-direction: column; } .upper1{ background-color: #c2ff76; width: 30vw; margin: 10px; height: 30vh; } .upper2{ display: flex; flex-direction: row; margin: 10px; } .box3{ background-color: #ff69b4; height: 35vh; width: 15vw; } .box4{ display: flex; flex-direction: column; } .box4a{ background-color: #9ba4ff; height: 15.5vh; width: 14.25vw; margin: 10px; } .box4b{ background-color: #9ba4ff; height: 15.5vh; width: 14.25vw; margin: 10px; }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="style.css"> <title>Flexbox</title> </head> <body> <div class="container"> <div class="box1"></div> <div class="box2"> <div class="upper1"></div> <div class="upper2"> <div class="inside"> <div class="box3"></div> </div> <div class="box4"> <div class="box4a"></div> <div class="box4b"></div> </div> </div> </div> </div> </body> </html>
希望你能理解。
olqngx593#
提示:您可以嵌套flexbox。
*{margin:0;padding:0;box-sizing:border-box;} .main, .main * {border: 1px solid gray;} .main { display: flex; width: 200px; height: 100px; } .red { background: red; display: flex; align-items: center; justify-content: center; width: 50%; height: 100%; } .flex1 { display: flex; flex-direction: column; width: 50%; height: 100%; } .green { background: green; display: flex; align-items: center; justify-content: center; width: 100%; height: 50%; } .flex2 { display: flex; width: 100%; height: 50%; } .pink { background: pink; display: flex; align-items: center; justify-content: center; width: 50%; height: 100%; } .flex3 { display: flex; flex-direction: column; width: 50%; height: 100%; } .blue { background: blue; display: flex; align-items: center; justify-content: center; width: 100%; height: 50%; }
<div class=main> <div class=red>1</div> <div class=flex1> <div class=green>2</div> <div class=flex2> <div class=pink>3</div> <div class=flex3> <div class=blue>4a</div> <div class=blue>4b</div> </div> </div> </div> </div>
o2g1uqev4#
你不能用flex来做这件事,除非你有很多容器div。下面是一个例子:
.outer { width: calc(100% - 30px); height: 200px; background-color: #d6d6d6; padding: 15px; } .gap { gap: 10px; } .flex { display: flex; } .column { flex-direction: column; } .box-1 { background-color: #ff7676; height: 100%; width: 33%; } .box-2 { width: 66%; } .box-4 > div, .box-2 > div { width: 100%; height: 50%; } .box-3 > div { width: 50%; height: 100%; } .box-4 > div { background-color: #9ba4ff; } .box-3 > div:first-child { background-color: pink; } .box-2 > div:first-child { background-color: #c2ff76; }
<div class="outer flex gap"> <div class="box-1"></div> <div class="flex column box-2 gap"> <div></div> <div class="flex box-3 gap"> <div></div> <div class="flex column box-4 gap"> <div></div> <div></div> </div> </div> </div> </div>
但在您的情况下,最好的选择是使用grid。
grid
4条答案
按热度按时间wd2eg0qa1#
这是你应该使用网格的东西,但是用flex也可以做到这一点,你只需要很多额外的容器div。
0kjbasz62#
如果你想要纯粹的flexbox风格,
希望你能理解。
olqngx593#
提示:您可以嵌套flexbox。
o2g1uqev4#
你不能用flex来做这件事,除非你有很多容器div。下面是一个例子:
但在您的情况下,最好的选择是使用
grid
。