在CSS网格布局中添加水平滚动

时间:2018-02-25 10:54:47

标签: css3 grid-layout css-grid

我想在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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:-2)

你好试着看看这个:

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;
}

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