HTML Divs, Columns, Horizontal Scroll Bar

荒凉一梦 提交于 2019-12-22 00:58:23

问题


I'm trying to display several chunks of data in columns next to each other. I have set the container to display inline, which works great if the columns are relatively thin. As soon as a column exceeds the horizontal screen length, the other columns get appended to the bottom.

My question is this: How can display inline column divs that are placed horizontally, with a horizontal scroll bar?

Note: I actually WANT the scroll bar; I want the elements side by side.

<div class="container">
    <div class="child" id="1">Stuff</div>
    <div class="child" id="2">Stuff</div>
</div>

---------

.child {
   /*float:left;
   margin-right:5em;*/
   display:inline;
}
.container {
   display:inline;
   overflow: scroll-x;
   white-space: nowrap;

}

Thanks,
Michael


回答1:


We're trying to keep the browser from doing it's normal job: layouting stuff in such a way that it fits into the current window-size. It doesn't matter if the stuff is block or inline, still the browser will try to fit it inside the window.

You can give your container a fixed width to ensure enough space for all the columns:

.child {
   margin-right:50px;
   float:left;
   width: 100px;
   border: 1px black solid;

}

.container {
   width: 1520px;
   overflow: scroll-x;
   border: 1px red solid;
}

example page

screenshot of the example page http://www.users.fh-salzburg.ac.at/~bjelline//css-layout/sidebyside.png




回答2:


I think chaos is correct it just may be overflow-x: scroll; instead



来源:https://stackoverflow.com/questions/1278796/html-divs-columns-horizontal-scroll-bar

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