情况:

 _______________________________________
|             .ParentContainer          |
|    _______      ____________          |
|   |       |    |            |         |
|   |.Block1|    |.Block2     |         |
|   |       |    |            |         |
|   |       |    |            |         |
|   |_______|    |            |         |
|                |            |         |
|                |            |         |
|                |            |         |
|                |            |         |
|                |____________|         |
|_______________________________________|


我需要在Block3之后动态添加Block2。更准确地说,在DOM中,它必须位于Block2之后,但在页面上,它必须出现在Block1下方。

所以我想看这样的东西:

 _______________________________________
|             .ParentContainer          |
|    _______      ____________          |
|   |       |    |            |         |
|   |.Block1|    |.Block2     |         |
|   |       |    |            |         |
|   |       |    |            |         |
|   |_______|    |            |         |
|                |            |         |
|    _______     |            |         |
|   |       |    |            |         |
|   |.Block3|    |            |         |
|   |       |    |            |         |
|   |       |    |____________|         |
|   |_______|                           |
|                                       |
|_______________________________________|


代码很简单:

<div class="ParentContainer clearfix">
    <div class="Block1 leftFloat></div>
    <div class="Block2 leftFloat></div>
</div>


我有jQuery,它将在block2之后附加下一个块(Block3),但我不确定如何通过此标记实现上述结果...

最佳答案

尝试这个想法,并使用jQuery的.after():

.ParentContainer div {
    float: left;
    clear: left;
}
div.Block2 {
    float:right;
    clear: none;
}


FIDDLE

10-06 15:20