简体   繁体   English

CSS 列,从上到下然后从左到右

[英]CSS Columns, Top to Bottom then Left to Right

I'm building a newspaper style layout for an app.我正在为应用程序构建报纸样式布局。 My page is split into 8 columns, and the columns should fill vertically first then horizontally.我的页面被分成 8 列,这些列应该先垂直填充然后水平填充。

If there isn't enough content to fill the page, the columns should still fill vertically first leaving white space to the right of the page.如果没有足够的内容来填充页面,列仍应垂直填充,首先在页面右侧留下空白。 Currently they fill horizontally first leaving white space bellow the content.目前,它们首先水平填充,在内容下方留下空白。

I've tried this with CSS columns but it seems to always fill the width of the page, I can't see a way to change this.我已经用 CSS 列尝试过这个,但它似乎总是填充页面的宽度,我看不到改变它的方法。

I've also tried with flex box, but flex wrap will not break/ wrap inside of a div like CSS columns will.我也尝试过使用 flex 框,但是 flex wrap 不会像 CSS 列那样在 div 内折断/换行。

.flex-col {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  max-height: 300px;

  p {
    width: 250px;
  }
}

.css-col {
  columns: 3;
}

See here for an example of what I have tried.有关我尝试过的示例,请参见此处。

Adding column-fill: auto;添加column-fill: auto; to .css-col should give you what you are looking for, but you need to add a height to .css-col to .css-col应该给你你正在寻找的东西,但你需要给.css-col添加一个height

You seem to be closing the divs too soon.您似乎过早地关闭了 div。 Perhaps inline-flex is closer.也许inline-flex更接近。 I'm not clear what this is supposed to look like otherwise我不清楚这应该是什么样子

 .flex-col { display: inline-flex; flex-direction: column; flex-wrap: wrap; max-height: 300px; } p { width: 250px; } }
 <div class="flex-col"> <p>The quick brown fox jumped over the small lazy dog. The quick brown fox jumped over the small lazy dog.</p> <p>The quick brown fox jumped over the small lazy dog. The quick brown fox jumped over the small lazy dog.</p> <p>The quick brown fox jumped over the small lazy dog. The quick brown fox jumped over the small lazy dog.</p> <p>The quick brown fox jumped over the small lazy dog. The quick brown fox jumped over the small lazy dog.</p> <p>The quick brown fox jumped over the small lazy dog. The quick brown fox jumped over the small lazy dog.</p> <p>The quick brown fox jumped over the small lazy dog. The quick brown fox jumped over the small lazy dog.</p> <p>The quick brown fox jumped over the small lazy dog. The quick brown fox jumped over the small lazy dog.</p> </div>

https://codepen.io/Paulie-D/pen/mpBNBg https://codepen.io/Paulie-D/pen/mpBNBg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM