简体   繁体   English

水平显示父div超出页面宽度

[英]Displaying parent div horizontally beyond width of page

<div class="parent">
  <div class="child">
  </div>
  <div class="child">
  </div>
  <div class="child">
  </div>
  <div class="child">
  </div>
  <div class="child">
  </div>
</div>

The height of the child class is 20% and the width 200px. 子类的高度为20%,宽度为200px。

What I'm wondering is how to make it so that when I have, for example, 20 parent divs it is set up so that they are all displayed horizontally, beyond the width of the page, so that I have to scroll left or right to view the data. 我想知道的是如何做到这一点,例如,当我有20个父div时,将其设置为使其全部水平显示,超出页面宽度,因此我必须向左或向右滚动查看数据。 At the moment it fills the width of the page and starts the next parent div underneath the first one so that I have to scroll vertically and I can't fathom how to rectify this problem. 目前,它填充了页面的宽度,并在第一个下一个div处开始,因此我必须垂直滚动,无法理解如何解决此问题。

Thanks in advance. 提前致谢。

To do this you need to create a parent container, and then assign a overflow-x: scroll css rule to it. 为此,您需要创建一个父容器,然后为其分配一个overflow-x: scroll scss规则。 You will also need to assign a display: inline-block rule to your parent class. 您还需要为您的parent类分配一个display: inline-block规则。 You also need to apply white-space: nowrap;. 您还需要应用空白:nowrap;。

DEMO http://jsfiddle.net/qujyunn4/ 演示http://jsfiddle.net/qujyunn4/

 .wrapper { overflow-x: scroll; white-space: nowrap; } .parent { display: inline-block; width: 200px; height: 300px; border: red solid thin; margin-right: 5px; white-space: nowrap; } 
 <div class="wrapper"> <div class="parent"> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> </div> <div class="parent"> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> </div> <div class="parent"> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> </div> <div class="parent"> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM