1

If I have two blocks with dynamic widths/heights, is there a way to line them up inside a parent element with a fixed width?

SEE: http://jsfiddle.net/QhEYB/

I want the blue/dynamic div to always resize depending on the size of the red element and to not go underneath the red. In other words, for the blue block to be a square block that sits next to the red one.

.wrap {width:600px; }/*static*/
.something {float:left; background:red; width:200px; height:100px;} /*dynamic width/height*/

.somethingelse { background:blue;} /*dynamic width/height and should always be next to .something*/

Thanks!

4

1 回答 1

2

使用display:tableand display:table-cell,您应该能够实现您想要的:

.wrap {width:600px; display:table; }/*static*/
.something {display:table-cell; background:red; width:200px; height:100px;} 
.somethingelse { background:blue; display:table-cell;} 

http://jsfiddle.net/QhEYB/3/

于 2013-07-24T11:20:05.170 回答