How to make horizontal scroll on page

谁说我不能喝 提交于 2020-01-01 05:05:59

问题


I have div in which placed inner divs i need to make all inner divs in line and horizontal scrollbar should be displayed (i know it sounds crazy, but i need that). I tried container width auto and overflow scroll but nothing.

How to accomplish that?

my markup:

   <!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>text-overflow</title>
  <style>
  body{
    width: auto;
  }
  #items{
  overflow-x: scroll;
  width: auto;
  }
  .item{
     display: inline-block;
     width: 400px;
     height: 100px;
     border:1px solid;
  }
  </style>
 </head>
 <body>

        <div id="items">
           <div class="item">
             Item content
           </div>
           <div class="item">
             Item content
           </div>
           <div class="item">
             Item content
           </div>
           <div class="item">
             Item content
           </div>
           <div class="item">
             Item content
           </div>
           <div class="item">
             Item content
           </div>
        </div>

 </body>
</html>

回答1:


Use white-space: nowrap; on #items

#items{
    overflow-x: scroll;
    width: auto;
    white-space: nowrap;
}

DEMO




回答2:


simply give #items to height and overflow-x:auto.

#items{
      overflow-x: auto;
      width: auto;
       height: 200px;
      }



回答3:


<div style="overflow-x:scroll;">
  <div style="width:1600px;">
    <div style="width:1500px;">
      <table>
        <tr>
          <td> your value <td>
        </tr>
      </table
    </div>
  </div>
</div>


来源:https://stackoverflow.com/questions/13379053/how-to-make-horizontal-scroll-on-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!