首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS列垂直溢出解决方法

CSS列垂直溢出解决方法
EN

Stack Overflow用户
提问于 2016-06-05 12:13:31
回答 3查看 1.2K关注 0票数 1

我尝试使用CSS列在相对固定的div中以列的方式排列图像。我希望div垂直滚动,但当它达到可用的最大垂直空间时,它会在右侧创建新列,强制div水平滚动,而不是保持3个预期的列并垂直溢出。有没有办法解决这个问题?

代码语言:javascript
复制
    body {
      background-color: white;
      width:100%;
      height:100%;
      position:absolute;
      font-family: "ff-tisa-web-pro",serif;
      font-size: 16px;
      font-weight: 400;
      line-height: 1.45;
      color: #333;
      background: rgba(200,125,06,0.5)
    }

    .grid {
      position:relative;
      height:80%;
      -webkit-columns: 150px;
      -moz-columns: 3 150px;
      columns: 3 150px;
      width:40%;
      margin:auto;
      overflow: auto;
      background: rgba(200,125,06,0.5);
      break-inside: avoid;
    }
  .grid img{
    width:100%;
  }
代码语言:javascript
复制
    <div class="grid">
      <img src="http://i.telegraph.co.uk/multimedia/archive/03434/guinness-eyeballs_3434500k.jpg"/>
      <img src="https://www.allindiaroundup.com/wp-content/uploads/2015/01/mr-bean-pics-as-a-baby-whatsapp-dp-1024x768.jpg"/>
      <img src="http://www.likecool.com/Gear/Pic/10%20Vintage%20Pics%20Of%20Carrie%20Fisher%20Promoting%20%20Return%20Of%20The%20Jedi%20%20In/10-Vintage-Pics-Of-Carrie-Fisher-Promoting--Return-Of-The-Jedi--In-2.jpg"/>
      <img src="http://8.mshcdn.com/wp-content/uploads/2012/10/steve-jobs-finger.jpg"/>
      <img src="https://www.funnypica.com/wp-content/uploads/2012/05/funny-picture-of-ugly-indian.jpg"/>
      <img src="http://i.telegraph.co.uk/multimedia/archive/03434/guinness-eyeballs_3434500k.jpg"/>
      <img src="https://www.allindiaroundup.com/wp-content/uploads/2015/01/mr-bean-pics-as-a-baby-whatsapp-dp-1024x768.jpg"/>
      <img src="http://www.likecool.com/Gear/Pic/10%20Vintage%20Pics%20Of%20Carrie%20Fisher%20Promoting%20%20Return%20Of%20The%20Jedi%20%20In/10-Vintage-Pics-Of-Carrie-Fisher-Promoting--Return-Of-The-Jedi--In-2.jpg"/>
      <img src="http://8.mshcdn.com/wp-content/uploads/2012/10/steve-jobs-finger.jpg"/>
      <img src="https://www.funnypica.com/wp-content/uploads/2012/05/funny-picture-of-ugly-indian.jpg"/>
    </div>

EN

回答 3

Stack Overflow用户

发布于 2016-06-05 12:59:19

尝试使用1列计数,当文本大于可用高度时,它将自动拆分到第二列- columns: 1 150px;

代码语言:javascript
复制
body {
    background-color: white;
    width:100%;
    height:100%;
    position:absolute;
    font-family: "ff-tisa-web-pro",serif;
    font-size: 16px;
    font-weight: 400;
    line-height: 1.45;
    color: #333;
    padding: 1em;
    overflow: hidden;
    background: rgba(200,125,06,0.5)
  }

  article {
    position:relative;
    height:70%;
    -webkit-columns: 150px;
    -moz-columns: 1 150px;
    columns: 1 150px;
    padding:1em;
    width:40%;
    margin:auto;
    overflow: scroll;
    background: rgba(200,125,06,0.5)
  }
代码语言:javascript
复制
<article>
    At noon they sat down by the roadside, near a little brook, and Dorothy opened her basket and got out some bread.  She offered a piece to the Scarecrow, but he refused.
    I am never hungry,&rdquo; he said, &ldquo;and it is a lucky thing I am not, for my mouth is only painted, and if I should cut a hole in it so I could eat, the straw I am stuffed with would come out, and that would spoil the shape of my head.&rdquo;
  Dorothy saw at once that this was true, so she only nodded and went on eating her bread.
  &ldquo;Tell me something about yourself and the country you came from,&rdquo; said the Scarecrow, when she had finished her dinner.  So she told him all about Kansas, and how gray everything was there, and how the cyclone had carried her to this queer Land of Oz.
   &ldquo;Tell me something about yourself and the country you came from,&rdquo; said the Scarecrow, when she had finished her dinner.  So she told him all about Kansas, and how gray everything was there, and how the cyclone had carried her to this queer Land of Oz.
   &ldquo;Tell me something about yourself and the country you came from,&rdquo; said the Scarecrow, when she had finished her dinner.  So she told him all about Kansas, and how gray everything was there, and how the cyclone had carried her to this queer Land of Oz.
    &ldquo;Tell me something about yourself and the country you came from,&rdquo; said the Scarecrow, when she had finished her dinner.  So she told him all about Kansas, and how gray everything was there, and how the cyclone had carried her to this queer Land of Oz.
   &ldquo;Tell me something about yourself and the country you came from,&rdquo; said the Scarecrow, when she had finished her dinner.  So she told him all about Kansas, and how gray everything was there, and how the cyclone had carried her to this queer Land of Oz.
   &ldquo;Tell me something about yourself and the country you came from,&rdquo; said the Scarecrow, when she had finished her dinner.  So she told him all about Kansas, and how gray everything was there, and how the cyclone had carried her to this queer Land of Oz.
  </article>

票数 1
EN

Stack Overflow用户

发布于 2016-06-05 13:41:08

让我们看看这是否对你有帮助。

代码语言:javascript
复制
body {
      background-color: white;      
      height:100%;
      position:absolute;
      font-family: "ff-tisa-web-pro",serif;
      font-size: 16px;
      font-weight: 400;
      line-height: 1.45;
      color: #333;
      background: rgba(200,125,06,0.5)
    }

    .grid {
      position:relative;     
      -webkit-columns:3 150px;
      -moz-columns: 3 150px;
      columns: 3 150px;      
      margin:auto;
      overflow: auto;
      background: rgba(200,125,06,0.5);
      break-inside: avoid;
    }
  .grid img{
    width:100%;
  }
代码语言:javascript
复制
<div class="grid">
      <img src="http://i.telegraph.co.uk/multimedia/archive/03434/guinness-eyeballs_3434500k.jpg"/>
      <img src="https://www.allindiaroundup.com/wp-content/uploads/2015/01/mr-bean-pics-as-a-baby-whatsapp-dp-1024x768.jpg"/>
      <img src="http://www.likecool.com/Gear/Pic/10%20Vintage%20Pics%20Of%20Carrie%20Fisher%20Promoting%20%20Return%20Of%20The%20Jedi%20%20In/10-Vintage-Pics-Of-Carrie-Fisher-Promoting--Return-Of-The-Jedi--In-2.jpg"/>
      <img src="http://8.mshcdn.com/wp-content/uploads/2012/10/steve-jobs-finger.jpg"/>
      <img src="https://www.funnypica.com/wp-content/uploads/2012/05/funny-picture-of-ugly-indian.jpg"/>
      <img src="http://i.telegraph.co.uk/multimedia/archive/03434/guinness-eyeballs_3434500k.jpg"/>
      <img src="https://www.allindiaroundup.com/wp-content/uploads/2015/01/mr-bean-pics-as-a-baby-whatsapp-dp-1024x768.jpg"/>
      <img src="http://www.likecool.com/Gear/Pic/10%20Vintage%20Pics%20Of%20Carrie%20Fisher%20Promoting%20%20Return%20Of%20The%20Jedi%20%20In/10-Vintage-Pics-Of-Carrie-Fisher-Promoting--Return-Of-The-Jedi--In-2.jpg"/>
      <img src="http://8.mshcdn.com/wp-content/uploads/2012/10/steve-jobs-finger.jpg"/>
      <img src="https://www.funnypica.com/wp-content/uploads/2012/05/funny-picture-of-ugly-indian.jpg"/>
    </div>

票数 1
EN

Stack Overflow用户

发布于 2020-06-24 03:25:47

我遇到了这个问题,解决方案是对父元素使用overflow-y:scroll (或auto),而不是对具有column-count的元素使用overflow-y:scroll(或auto),因为两者似乎不兼容。

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

https://stackoverflow.com/questions/37638379

复制
相关文章

相似问题

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