子Div溢出x - y并在父级滚动

时间:2013-09-16 08:05:34

标签: html css overflow

HTML:

<div id="parent">
   <div id="child">

      <ul>
         <li>one</li>
         <li>A very long name. A very long name. A very long name. A very long name. A very long name. A very long name. </li>
         <li>Three</li>
      </ul>

   </div>    
</div>

CSS:

#parent {width:170px; border:1px solid #000; padding:20px}
#child {border:1px solid #F00}

我没有将宽度属性应用于子div。我想要的是在父div上看到水平和垂直滚动条。

小提琴:http://jsfiddle.net/NanzR/

预期产量: enter image description here

1 个答案:

答案 0 :(得分:4)

以下是一个例子:

jsfiddle Demo

#parent {
    width:170px;
    overflow: scroll;
    height: 170px;
}
#child {
    overflow: hidden;
    display: inline-block;
    min-width: 100%;
}