我有父div(滑塊)的高度:450px和寬度:960px,其中有子div(pannel)的隨機數(這裏讓我們考慮5)相同的高度和寬度。包含水平子div數的特定高度和寬度的父div
它們必須水平排列在父div中,這樣一次只有一個div適合父div,也只有overflow-x:auto;沒有垂直滾動條。
這是我到目前爲止有:
HTML
<div class="slider_holder">
<div class="slider">
<span class="pannel"> </span>
<span class="pannel"> </span>
<span class="pannel"> </span>
<span class="pannel"> </span>
<span class="pannel"> </span>
</div>
</div>
CSS
html, body, *
{
margin:0px;
width:100%;
}
.slider_holder
{
margin-left:auto;
margin-right:auto;
display:block;
position:relative;
top:100px;
width:960px;
height:450px;
background:#eee;
overflow:auto;
}
.slider
{
width:auto;
height:100%;
}
.pannel
{
display:inline-block;
float:left;
width:960px;
height:100%;
border:1px solid red;
}
注意:我能實現我想要什麼,如果我給寬度:4800px;滑塊div爲5x960 = 4800,但我不想這個硬編碼,因爲子div的數量可以是任何數字。
我不希望它垂直排列div,我希望它在水平方向排列滑塊div。 [像這樣](http://www.divyashah.in/stackoverflow/horizontalscroll.png) – divy3993
@ divy3993我知道。你檢查過小提琴嗎?您還應該從'.pannel'類中刪除'float:left'類 –
非常感謝,它對我非常有用,但我想了解它的功能。請 ! – divy3993