简体   繁体   中英

How to stack two dynamic sized blocks to be side-by-side?

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!

With the use of display:table and display:table-cell , you should be able to achieve what you want:

.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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM