CSS width 100% including overflow

泪湿孤枕 提交于 2019-12-06 18:42:33

问题


For various reasons, I have a nested ol inside of a div, where the contents of the list exceeds the size of the container.

Because the container has a fixed width, the list element's background does not exceed the viewable area of the container, yet the contents scroll properly.

I have created a jsFiddle showing a simplified example of what I'm trying to explain.

I would like the width of the contained element to match that of the overflowed content. In the jsFiddle, that would mean the red background doesn't get cut off midway.

Thanks.

div
{
    border: 1px solid black;
    margin: 33% auto;
    overflow: scroll;
    white-space: nowrap;
    width: 100px;
}

div > ol
{
   background: red;
   width: 100%;
}​

回答1:


Just use display: inline-block. You can read more in the W3C specs.

Replace width:100% with display:inline-block in those two element styles.



来源:https://stackoverflow.com/questions/12719997/css-width-100-including-overflow

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