html5 wrap= off,css - HTML divs, how to wrap content? - Stack Overflow

Seeing as everyone luuuuuuurves jQuery, I decided to throw something together that actually does what you asked. Have fun :)

Test

Test

Test

Test

Test

Test

Test

Test

Test

Test

Test

Test

Throw in some css

#div1, #div2, #div3, #div4 {

border:3px double #000;

background:#fff

}

#div1 {

width:200px;

float:left;

}

#div4 {

clear:both;

}

And finally your jQuery.

$(function () {

$('#div2').css({

marginLeft: $('#div1').outerWidth()

});

if ($('#div2').height() < $('#div1').height()) {

$('#div3').css({

marginLeft: $('#div1').outerWidth()

});

}

});

Now. I am not advocating this method, just saying that it actually achieved what you asked for whereas nothing else here has ;)

See it at this jsFiddle. Simply add one more

Test

to div1 and you will see that div3 then goes to the right of div1 as per your image.

Now, I know someone will say "But div1 doesn't take all the height then!", well fear not. Check the updated jsFiddle with one added piece to the javascript to see your questions answered too. Just delete one of the

Test

from div1.

$(function () {

$('#div2').css({

marginLeft: $('#div1').outerWidth()

});

if ($('#div2').height() < $('#div1').height()) {

$('#div3').css({

marginLeft: $('#div1').outerWidth()

});

$('#div1').css({

height: $('#div2').outerHeight() + $('#div3').height()

});

}

});

I have to reiterate that this solution relies on Javascript. Turn it off, device doesnt support it, this stops working.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值