【发布时间】:2019-08-07 16:01:55
【问题描述】:
是否可以使用 CSS3 Flexbox 实现如下图所示的响应式设计布局?我可以使用下面的代码实现桌面布局。但是,我想不出办法让 div #div3 和 #div4 填充在 #div1 和 #div2 下方
编辑:很抱歉,我忘了提到它不仅限于 CSS Flexbox,而且网格解决方案似乎更灵活,所以我将其标记为已接受的答案。谢谢大家的帮助!
我的代码
#div1 {
background-color: red;
width: 100px;
height: 100px;
}
#div2 {
background-color: green;
width: 100px;
height: 100px;
}
#div3 {
background-color: orange;
width: 100px;
height: 100px;
}
#div4 {
background-color: blue;
width: 100px;
height: 100px;
}
.container,
#flex-container {
display: flex;
}
#flex-container {
flex-direction: column;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="test.css">
</head>
<body>
<div class="container">
<div id='div1'></div>
<div id="flex-container">
<div id='div2'></div>
<div id='div3'></div>
<div id='div4'></div>
</div>
</div>
</body>
</html>
【问题讨论】:
-
可以使用新的网格css布局(显示:网格)吗?使用网格会很容易......