css – 如何在flex列换行布局中启动一个新列

栏目: CSS · 发布时间: 6年前

内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/27119691/how-to-start-a-new-column-in-flex-column-wrap-layout

我希望我的数据按列排列(从上到下,从左到右),数据中的每个标题都应该开始一个新的列.有三个限制:

>必须使用flex(我需要使用特定于flex的功能)

>无法对数据进行分组(例如,将所有数据项包含在一个div内)

>无法设定固定高度

我的问题是如何在flex-flow:列换行布局中强制列中断?

.grid {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
}
.grid .head {
  width: 25%;
  background: orange;
  border-bottom: thin dotted;
}
.grid .data {
  width: 25%;
  background: yellow;
  border-bottom: thin dotted;
}
/* my attempt to solve this */
.grid {
  height: 76px;
}
<div class="grid">
  <div class="head">Column 1 (3 items)</div>
  <div class="data">item 1-1</div>
  <div class="data">item 1-2</div>
  <div class="data">item 1-3</div>
  <div class="head">Column 2 (4 items)</div>
  <div class="data">item 2-1</div>
  <div class="data">item 2-2</div>
  <div class="data">item 2-3</div>
  <div class="data">item 2-4</div>
  <div class="head">Column 3 (2 items)</div>
  <div class="data">item 3-1</div>
  <div class="data">item 3-2</div>
  <div class="head">Column 4 (1 items)</div>
  <div class="data">item 4-1</div>
</div>
显然, the correct solution is to use the break-before or break-after property

A break is forced wherever the CSS2.1  07001/07002 [CSS21] or the CSS3  07003/07004 [CSS3-BREAK] properties specify a  fragmentation break.

在撰写本文时,大多数浏览器都会错误地实现* -break- *属性,或者根本不实现它们.在此之前考虑这个答案.

以下演示工作原理:

> FF33

.grid {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
}
.grid .head {
  width: 25%;
  background: orange;
  border-bottom: thin dotted;
}
.grid .data {
  width: 25%;
  background: yellow;
  border-bottom: thin dotted;
}
/* force column breaks */
.grid .head:nth-child(n + 2) {
  page-break-before: always; /* FF33 */
}
<div class="grid">
  <div class="head">Column 1 (3 items)</div>
  <div class="data">item 1-1</div>
  <div class="data">item 1-2</div>
  <div class="data">item 1-3</div>
  <div class="head">Column 2 (4 items)</div>
  <div class="data">item 2-1</div>
  <div class="data">item 2-2</div>
  <div class="data">item 2-3</div>
  <div class="data">item 2-4</div>
  <div class="head">Column 3 (2 items)</div>
  <div class="data">item 3-1</div>
  <div class="data">item 3-2</div>
  <div class="head">Column 4 (1 items)</div>
  <div class="data">item 4-1</div>
</div>

代码日志版权声明:

翻译自:http://stackoverflow.com/questions/27119691/how-to-start-a-new-column-in-flex-column-wrap-layout


以上所述就是小编给大家介绍的《css – 如何在flex列换行布局中启动一个新列》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

云经济学

云经济学

乔·韦曼 (Joe Weinman) / 人民邮电出版社 / 2014-7-1 / CNY 75.00

在云计算日益成熟的今天,“接入而非拥有”的理念不断为人们所理解和接受。 《云经济学》阐述了“云经济学”不是经济理论中深奥的数学模型,而是技术革命的生动概括。“灵活的云计算能够有效提升企业的商业价值”则是本书的核心理念。 《云经济学——企业云计算战略与布局》从商业、金融及经济的视角解释了云经济的潜在原理,并通过易于理解的案例阐述了云计算是如何创造出综合价值的。无论你是供应商、零售商、服务......一起来看看 《云经济学》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具