3

我有水平滚动列。里面有一些带有标题的文本。我需要让每个标题生成一个新列并占用属于它的列上方的所有空间:

预期结果
或者:
替代预期结果

但我能做的最好的事情是(顺便说一下,它在 Firefox 中失败了):

Chrome 中的实际结果

尝试使用inline-blocks存档所需的结果,但那里出现了另一个问题。我还尝试了一些负边距、绝对定位和 的方法transform,但没有成功:它们不允许超出列(除了absolute容器上下文:它忘记了基于列的水平定位)。

最简单的代码https://jsfiddle.net/07n6L2yh/10/

.container {
  outline: 1px dotted gray;
  height: 200px;
  -moz-column-width: 10em;
  column-width: 10em;
  -moz-column-fill: auto;
  column-fill: auto;
  overflow-x: auto;
}

h2 {
  break-before: column; /* Firefox? */
  border-bottom: 1px solid;
  margin: 0 0 .25em;
}

p {
  margin: 0;
}
<div class="container">
  <h2>Lorem ipsum</h2>
  <p>Lorem ipsum dolor sit amet, eu eirmod complectitur pri, agam libris euripidis no quo. In cum adolescens necessitatibus, et hinc nominati indoctum his, idque prompta moderatius cu per. Quo ei novum utroque, ius ex graecis volutpat quaerendum! Ea assum erroribus accommodare pri, simul omnesque scaevola has cu, an putant tacimates ius. Ius soluta nonumes ei? Ex modus eligendi repudiandae ius, nec cu quem delicatissimi.</p>

  <h2>AAA</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, explicabo.</p>

  <h2>Dolor sit</h2>
  <p>Lorem ipsum dolor sit amet, eu eirmod complectitur pri, agam libris euripidis no quo. In cum adolescens necessitatibus, et hinc nominati indoctum his, idque prompta moderatius cu per. Quo ei novum utroque, ius ex graecis volutpat quaerendum!</p>

  <h2>BBB</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>

  <h2>CCC</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
</div>

更复杂的版本:https ://jsfiddle.net/07n6L2yh/11/

PS:俄语中的同​​样问题。

4

3 回答 3

5

.container {
  outline: 1px dotted red;
  height: 200px;
  min-width: 650px;
  display: flex;
  overflow-x: scroll;
}

h2 {
  break-before: column; /* Firefox? */
  border-bottom: 1px solid;
  margin: 0 0 .25em;
}

p {
  margin: 0;
  -moz-column-width: 7em;
  column-width: 7em;
  -moz-column-rule: fill;
  column-rule: fill;
  overflow-x: auto;
  display: block;
  font-size: 10px;
}
.each-sec{
  padding: 1em;
}
<div class="container">
  <div class="each-sec">
<h2>Lorem ipsum</h2>
<div>
  <p>Lorem ipsum dolor sit amet, eu eirmod complectitur pri, agam libris euripidis no quo. In cum adolescens necessitatibus, et hinc nominati indoctum his, idque prompta moderatius cu per. Quo ei novum utroque, ius ex graecis volutpat quaerendum! Ea assum erroribus accommodare pri, simul omnesque scaevola has cu, an putant tacimates ius.</p>
</div>
  </div>
  <div class="each-sec">
  <h2>AAA</h2>
  <div>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, explicabo.</p>
  </div>
  </div>
  <div class="each-sec">
  <h2>Dolor sit</h2>
  <div>
  <p>Lorem ipsum dolor sit amet, eu eirmod complectitur pri, agam libris euripidis no quo. In cum adolescens necessitatibus, et hinc nominati indoctum his, idque prompta moderatius cu per. Quo ei novum utroque, ius ex graecis volutpat quaerendum!</p>
  </div>
  </div>
  <div class="each-sec">
<h2>Lorem ipsum</h2>
<div>
  <p>Lorem ipsum dolor sit amet, eu eirmod complectitur pri, agam libris euripidis no quo. In cum adolescens necessitatibus, et hinc nominati indoctum his, idque prompta moderatius cu per. Quo ei novum utroque, ius ex graecis volutpat quaerendum! Ea assum erroribus accommodare pri, simul omnesque scaevola has cu, an putant tacimates ius.</p>
</div>
  </div>
</div>

如果您希望所有列的宽度相同,请将 css 添加到类中each-div

.each-sec{
  padding: 1em;
  flex: 1;
 }
于 2016-07-27T12:07:29.340 回答
1

使用这个简单的方法

.container {
  outline: 1px dotted gray;
  height: 200px;
  -moz-column-width: 10em;
  column-width: 10em;
  -moz-column-rule: fill;
  column-rule: fill;
  overflow-x: auto;
}

h2 {
  break-before: column; /* Firefox? */
  border-bottom: 1px solid;
  margin: 0 0 .25em;
}

p {
  margin: 0;
}
.left
{
min-height: 100%;
}
<div class="container">
  <div class="left">
  <h2>Lorem ipsum</h2>
  <p>Lorem ipsum dolor sit amet, eu eirmod complectitur pri, agam libris euripidis no quo. In cum adolescens necessitatibus, et hinc nominati indoctum his, idque prompta moderatius cu per. Quo ei novum utroque, ius ex graecis volutpat quaerendum! Ea assum erroribus accommodare pri, simul omnesque scaevola has cu, an putant tacimates ius. Ius soluta nonumes ei? Ex modus eligendi repudiandae ius, nec cu quem delicatissimi.</p>
</div>
<div class="left">
  <h2>AAA</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, explicabo.</p>
</div>
  <h2>Dolor sit</h2>
  <p>Lorem ipsum dolor sit amet, eu eirmod complectitur pri, agam libris euripidis no quo. In cum adolescens necessitatibus, et hinc nominati indoctum his, idque prompta moderatius cu per. Quo ei novum utroque, ius ex graecis volutpat quaerendum!</p>
<div class="left">
  <h2>BBB</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
</div>
<div class="left">
  <h2>CCC</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p></div>
</div>

方法

于 2016-07-27T12:32:28.150 回答
0

* {
  padding: 0;
  margin: 0;
}

.container {
  width: 600px;
  border: 1px solid;
  
  white-space: nowrap;
  
  overflow-x: scroll;
}

.article {  
  display: inline-block;
  vertical-align: top;
  outline: 1px solid red;
}

.article__title {
  font-size: 200%;
  border-bottom: 1px solid;
}

.article__body {
  -webkit-column-width: 10em;
     -moz-column-width: 10em;
          column-width: 10em;
  white-space: normal;
}
<div class="container">
  <div class="article">
    <h1 class="article__title">Title</h1>
    <div class="article__body">
      <p>SS Washingtonian was a cargo ship launched in 1913 by the Maryland Steel Company, one of eight sister ships for the American-Hawaiian Steamship Company and the largest</p>
    </div>
  </div>
  <div class="article">
    <h1 class="article__title">Title</h1>
    <div class="article__body">
      <p>SS Washingtonian was a cargo ship launched in 1913 by the Maryland Steel Company, one of eight sister ships for the American-Hawaiian Steamship Company and the largest cargo ship under American registry at the time. During the American occupation of Veracruz in April 1914, the ship was chartered by the Department of the Navy for service as a refrigerated supply ship for the U.S. fleet stationed off the Mexican coast cargo ship under American registry at the time. During the American occupation of Veracruz in April 1914, the ship was chartered by the Department of the Navy for service as a refrigerated supply ship for the U.S. fleet stationed off the Mexican coast..</p>
    </div>
  </div>
  <div class="article">
    <h1 class="article__title">Title</h1>
    <div class="article__body">
      <p>SS Washingtonian was a cargo ship launched in 1913 by the Maryland Steel Company, one of eight sister ships for the American-Hawaiian Steamship Company and the largest cargo ship under American registry at the time. During the American occupation of Veracruz in April 1914, the ship was chartered by the Department of the Navy for service as a refrigerated supply ship for the U.S. fleet stationed off the Mexican coast.</p>
    </div>
  </div>
</div>

于 2016-07-27T12:07:58.963 回答