UPDATE:这适用于我,我刚刚试了一下:
<div style="max-width:980px;border:1px solid red;">
<div style="background:#EEE;float:left;">
<div style="width:auto;border:1px solid blue;float:left;">If you use 100% here, it will fit to the width of the mother div automatically.</div>
<div style="border:1px solid green;"> The div will be 100% of the mother div too.</div>
</div>
<div style="clear:both;"></div>
</div>
这是你想要的吗?边框和背景都只是为了显示的div)
只要是这样的:
比方说,你想整个的div是最大。 980px(否则只留下了这一点或100%替代)...
<div style="max-width:980px;">
<div style="width:100%;">If you use 100% here, it will fit to the width of the mother div automatically.
</div>
<div style="width:100%;"> The div will be 100% of the mother div too.
</div>
</div>
第二个选择是,用一个多格...或者你使用style="width:auto;"
的动态格...
DIV是块元素这是他们自动采取他的父母宽度。检查这个http://jsfiddle.net/qG7b8/ – sandeep 2012-03-19 11:51:38
它的确如此。两个内部div的宽度最大化以适合其父宽度。这可能不是你的意思... – 2012-03-19 11:53:59
感谢您的意见。 我给了包装div一个显示:内联属性,这意味着它需要它的最宽的孩子的宽度。 现在我需要的是第二个子div取第一个子div的宽度。 – user1278456 2012-03-19 11:58:11