【问题标题】:Add horizontal scroll in CSS Grid Layout在 CSS 网格布局中添加水平滚动
【发布时间】:2018-02-25 10:54:47
【问题描述】:

我想在 CSS 网格布局中创建一个图片库,我需要为不可见的图片添加一个水平滚动条。我希望图像块不是添加到底部,而是添加到右侧。

.wrapper {
  display: grid;
  grid-template-rows: repeat(3, 33.34%);
  grid-template-columns: repeat(4, 25vw);
  grid-gap: 10px;
  height: 100vh;
}

.box1 {
  grid-column-start: 1;
  grid-column-end: 3;
}

.box2 {
  grid-column-start: 3;
  grid-column-end: 4;
  grid-row-start: 1;
  grid-row-end: 3;
}

.box8 {
  grid-column-start: 2;
  grid-column-end: 4;
}
<body>
<div class="wrapper">
    <div class="box1" style="background-image: url(https://placeimg.com/1000/500/animals); background-repeat: no-repeat; background-size: cover;"> </div>
    <div class="box2" style="background-image: url(https://placeimg.com/1000/500/sepia); background-repeat: no-repeat; background-size: cover;"> </div>
    <div class="box3" style="background-image: url(https://placeimg.com/1000/500/tech); background-repeat: no-repeat; background-size: cover;"> </div>
    <div class="box4" style="background-image: url(https://placeimg.com/1000/500/any); background-repeat: no-repeat; background-size: cover;"> </div>
    <div class="box5" style="background-image: url(https://placeimg.com/1000/500/people); background-repeat: no-repeat; background-size: cover;"> </div>
    <div class="box6" style="background-image: url(https://placeimg.com/1000/500/nature); background-repeat: no-repeat; background-size: cover;"> </div>
    <div class="box7" style="background-image: url(https://placeimg.com/1000/550/any); background-repeat: no-repeat; background-size: cover;"> </div>
    <div class="box8" style="background-image: url(https://placeimg.com/1000/500/architecture); background-repeat: no-repeat; background-size: cover;"> </div>
    <div class="box9" style="background-image: url(https://placeimg.com/1000/500/any); background-repeat: no-repeat; background-size: cover;"> </div>
    <div class="box10" style="background-image: url(https://placeimg.com/1000/500/grayscale); background-repeat: no-repeat; background-size: cover;"> </div>
</div>

【问题讨论】:

标签: css grid-layout css-grid


【解决方案1】:

你好试试看这个:

https://codepen.io/andybarefoot/pen/ypXYVJ

    #grid {
  writing-mode: vertical-lr;
  display: grid;
  grid-gap: 2vh; 
  grid-auto-rows: 1.52vh;
  grid-template-columns: repeat(5, 17.6vh);
  grid-auto-flow: row;
  text-align: center;
}

它可以帮助你重写你的网格:-)

【讨论】:

    猜你喜欢
    • 2018-10-04
    • 1970-01-01
    • 2017-10-08
    • 2013-10-18
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多