问题
I have the following code:
HTML
<div id="parent">
<div class="child">2001</div>
<div class="child">2O02</div>
<div class="child">2003</div>
<div class="child">2004</div>
<div class="child">2005</div>
</div>
CSS
#parent{
width:100%;
overflow:auto;
}
.Child{
float:left;
width:20px;
}
The child content is always overflowing, and this is good. But I want to be able to scroll horizontally in the parent div, to see the last child divs.
Here is a screenshot of the result as I have it:
Screenshot
How can I do that to make is scroll horizontally?
回答1:
If you want all childs in a single row, you have to add second "parent" DIV and set it's width (combined widths of all children for a single row):
HTML:
<div id="parent">
<div id="parent2">
<div class="child">2001</div>
<div class="child">2002</div>
<div class="child">2003</div>
<div class="child">2004</div>
<div class="child">2005</div>
</div>
</div>
CSS:
#parent{
width:100%;
overflow:auto;
}
#parent2{
width:1000px;
}
.child{
float:left;
width:200px;
}
来源:https://stackoverflow.com/questions/24190204/horizontal-scroll-in-a-parent-div-containing-floated-child-divs