horizontal scroll of inline-block element

后端 未结 3 499
情歌与酒
情歌与酒 2021-01-11 17:41

I have inline-block divs however when they reach end of the screen, they go the next line instead of scrolling horizontally, can someone help me out? here is a fiddle

<
3条回答
  •  盖世英雄少女心
    2021-01-11 18:15

    What about a bit more state-of-the-art solution using transform?

    HTML

    item 1
    item 2
    item 3
    item 4
    item 5
    item 6
    item 7
    item 8
    item 9
    item 10

    CSS

    div {
      box-sizing: border-box;
    }
    
    .horizontal-scroll-wrapper {
      background: #abc;
      display: block;
      max-height: 500px;
      overflow-y: auto;
      overflow-x: hidden;
      padding-top: 60px;
      position: absolute;
      transform: rotate(-90deg) translateY(-80px);
      transform-origin: right top;
    }
    
    .horizontal-scroll-wrapper > div {
      background: #cab;
      height: 60px;
      margin: 10px;
      padding: 5px;
      transform: rotate(90deg);
      transform-origin: right top;
      width: 60px;
    }
    

    CodeSandbox, inspired by https://css-tricks.com/pure-css-horizontal-scrolling/

提交回复
热议问题