【问题标题】:Width of Parent Div = Maximum Width of Child Divs?父 Div 的宽度 = 子 Div 的最大宽度?
【发布时间】:2014-09-05 14:00:43
【问题描述】:

我可以让父 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>

【问题讨论】:

    标签: javascript html css layout web


    【解决方案1】:

    制作容器display:inline-block

    JSfiddle Demo

    .container {
        background: green;
        overflow: hidden;
        max-width: 430px;
        display: inline-block; /* add this */
    }
    

    【讨论】:

    • 不幸的是,在这种情况下似乎不起作用:picpaste.com/Capture-cXRMo8bd.PNG
    • 很抱歉。我的意思是,在屏幕截图的情况下,绿色不应超出蓝色。我希望父母与最宽的孩子一样宽,而不是更宽。
    猜你喜欢
    • 2013-06-25
    • 2012-12-13
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    相关资源
    最近更新 更多