伸展父节点到其内容宽度 [英] Stretch parent node to its content width
本文介绍了伸展父节点到其内容宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div style='width:100%;background-color:green;padding:10px;'>
<div style='width: 5000px;background-color:red; padding:5px;'>
</div>
</div>
外部div固定在窗口的100%,而内部的div全宽。
Outer div is fixed at 100% of window, while inner one is rendered at full width.
有任何方法让外部div扩展到内部的宽度(如果它是大的),同时保持在窗口的至少100%如果inner div小)?
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)?
我不能使用 overflow-x:scroll - 只允许窗口滚动。此外,最小宽度:100%没有解决我的问题。
I cannot use overflow-x:scroll - only window scroll is allowed. Also min-width:100% didn't solve my problem.
如果没有解决方案,我可以使用JS resize事件。 >
If no solution exists I can use JS resize event.
推荐答案
尝试 display:table
for outer div
try display:table
for outer div
这篇关于伸展父节点到其内容宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文