我可以让父div的宽度自动等于其子div的最大宽度吗? IE。我希望父级与最宽的子级一样宽,而不是更宽。我可以接受纯 css 和 javascript 解决方案。
特别是,I have a parent div with two floating divs inside 。我希望当右侧 div 下降到下方时(如果窗口变得太窄)调整父 div 的大小,以使父 div 的背景正确显示。
谢谢!
<div class="container">
<div class="logo-div">
<img class="logo" src="http://bit.ly/1qCKrtJ" />
</div>
<div class="text-div">
<h4 style="display: inline;">Because Sometimes It Takes a Village</h4><br />
What about robots the size of tea cups that scoot around on tiny wheels, snapping pictures with miniature cameras and keeping track of where they are in relation to dozens of others?
</div>
</div>
最佳答案
使容器display:inline-block
.container {
background: green;
overflow: hidden;
max-width: 430px;
display: inline-block; /* add this */
}
关于javascript - 父 Div 的宽度 = 子 Div 的最大宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24757105/