首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flex列不匹配

Flex列不匹配
EN

Stack Overflow用户
提问于 2017-05-29 08:59:23
回答 1查看 142关注 0票数 2

我有两排折叠式。第一行有6个与flex: 1相等的列。第二行的列具有flex: 4,列具有flex:2。列有margin-right: 10px集,但行中的最后一个子列除外。

http://jsbin.com/gufihoyaha/edit?html,css,output

代码语言:javascript
复制
.row {
  display: flex;
}

.row .col {
  margin-right: 10px;
  background-color: coral;
}

.row .col:last-child {
  margin-right: 0;
}

.flex-1 {
  flex: 1;
}

.flex-4 {
  flex: 4;
}

.flex-2 {
  flex: 2;
}
代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<div class="row">
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
</div>
<div class="row">
  <div class="col flex-4">4</div>
  <div class="col flex-2">2</div>
</div>
</body>
</html>

但结果与我所预期的不同:

我想要的是这样的:

问:为什么会发生这种情况,以及如何解决?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-29 09:14:50

实际上,只有display:grid才能正确地做到这一点:

不幸的是,在这个时候,它是安静的,新的,没有实现的每一个地方。请参阅http://caniuse.com/#search=grid

要了解更多信息,请访问https://css-tricks.com/snippets/css/complete-guide-grid/

代码语言:javascript
复制
.row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
}

.row .col {
  background-color: coral;
  margin-right: 10px;
}

.row .col:last-child {
  margin-right: 0;
}

.flex-1 {}

.flex-4 {
  grid-column: auto / span 4;
}

.flex-2 {
  grid-column: auto / span 2;
}
代码语言:javascript
复制
<div class="row">
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
  <div class="col flex-1">1</div>
</div>
<div class="row">
  <div class="col flex-4">4</div>
  <div class="col flex-2">2</div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44238464

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档