【发布时间】:2018-11-01 21:40:58
【问题描述】:
我有一个工作面试的技术测试,我正在为应该是一个简单的布局而苦恼!
我需要一个两列设计,其中按 div 彼此堆叠:
然后对于较小的屏幕将更改为:
我以为我很了解 flexbox,但事实证明我显然不知道,我能得到的最接近的(这是不近...)是
使用
<head>
<style>
.container{
width:600px;
min-height:300px;
background-color: blue;
display:flex;
flex-wrap: wrap;
}
.small{
width: 100px;
height:100px;
background-color: darkgoldenrod;
margin:20px;
}
.big{
width: 250px;
height:250px;
background-color: green;
margin:20px;
}
</style>
</head>
<body>
<div class="container">
<div class="big">Widget 1</div>
<div class="small">Widget 2</div>
<div class="small">Widget 3</div>
<div class="big">Widget 4</div>
<div class="small">Widget 5</div>
<div class="small">Widget </div>
</div>
</body>
我已经搜索了几个小时,但我无法找到任何接近的东西!谁能指出我正确的方向?
【问题讨论】:
-
示例图形看起来像是在使用浮动而不是弹性框,tbh。无论如何,媒体查询会被视为作弊吗?
-
是否必须使用 flexbox?还是也允许网格?
-
如果没有额外的包装器和
display:contents,flexbox 中的多个布局是不可能的。