horizontal scroll of inline-block element

后端 未结 3 491
情歌与酒
情歌与酒 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 17:58

    Hide the y overflow and use nowrap

    .dx {
        height: 100px;
        overflow-y: hidden;
        white-space: nowrap;
        width: 100%;
    }
    

    FIDDLE

    0 讨论(0)
  • 2021-01-11 18:02

    Use white-space: nowrap; on dx class.

    Fiddle

    .dx{
        width:100%;
        height:100px;
        overflow:scroll;
        white-space: nowrap;
    }
    
    0 讨论(0)
  • 2021-01-11 18:15

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

    HTML

    <div class="horizontal-scroll-wrapper">
      <div>item 1</div>
      <div>item 2</div>
      <div>item 3</div>
      <div>item 4</div>
      <div>item 5</div>
      <div>item 6</div>
      <div>item 7</div>
      <div>item 8</div>
      <div>item 9</div>
      <div>item 10</div>
    </div>
    

    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/

    0 讨论(0)
提交回复
热议问题