Stretch parent node to its content width

社会主义新天地 提交于 2019-12-12 03:38:40

问题


<div style='width:100%;background-color:green;padding:10px;'>
  <div style='width: 5000px;background-color:red; padding:5px;'>
  </div>
</div>

http://jsfiddle.net/8xqwW/2/

Outer div is fixed at 100% of window, while inner one is rendered at full width.

Is there any way to make outer div to stretch to the inner one's width (if it is big) while remaining at at least 100% of the window (if inner div is small)?

I cannot use overflow-x:scroll - only window scroll is allowed. Also min-width:100% didn't solve my problem.

If no solution exists I can use JS resize event.


回答1:


try display:table for outer div



来源:https://stackoverflow.com/questions/14218445/stretch-parent-node-to-its-content-width

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