css - Flex Layout 混合行和列
问题描述
我可以float
轻松使用此布局。但很难用弹性盒子做。
CSS:
.a {
background: red;
float: left;
width: 30%;
height: 100px;
}
.b,
.c {
background: green;
overflow: hidden;
height: 45px;
}
.b {
margin-bottom: 10px;
}
.c {
background: lightblue
}
html:
<div class="a">column</div>
<div class="b">row1</div>
<div class="c">row2</div>
提前谢谢了。
解决方案
它是如何工作的?
main
将列包装在具有高度集的公共父级(例如元素)中。然后将元素放置在和 之间,并在和flex-direction: column
之间创建一个空间。b
c
justify-content: space-between
列的高度a
是100%
容器的高度,因此b
可以转移到新列中,c
这要归功于flex-wrap: wrap
CSS
main {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: space-between;
height: 100px;
}
.a {
background: red;
height: 100%;
width: 30%;
}
.b, .c {
background: green;
height: 45px;
width: 70%;
}
.c {
background: lightblue
}
它是如何工作的?
您可以通过Grid Layout
创建包含10
列和2
行的布局b
以及c
. row-gap: 10px
然后调整所有各种 ( column|row
)-( start|end
)
CSS
main {
display: grid;
grid-template-columns: repeat(10, 1fr);
row-gap: 10px;
width: 100%;
}
.a {
background: red;
grid-area: 1 / 1 / 3 / 3;
}
.b,
.c {
grid-column: 3 / 11;
background: green;
overflow: hidden;
height: 45px;
}
.b {
grid-row-start: 1;
}
.c {
grid-row-start: 2;
background: lightblue;
}
推荐阅读
- java - 如何在firebase实时数据库中引用特定节点
- python - 使用 Beautiful Soup 抓取一系列新闻文章 - 显示所有文章的问题。完整代码如下
- php - 数组中唯一值的总和
- powershell - 获取所有登录计算机的用户
- spring-boot - 有没有办法将业务中心嵌入自定义 Spring Boot 应用程序中?
- c# - 我试图在 C# 控制台中编写一个小程序来读取 xml 文件的某些部分,但我得到一个错误
- amazon-web-services - AWS ECS CI/CD 停机时间
- javascript - DIV内的背景图片重复
- kotlin - 由于不同的列表对象导致重复代码
- c# - ASP.NET Core 5.0 RouteDataRequestCultureProvider 删除 url 中的默认区域性