默认下,系统会安装用户所绘制的元素产生HTML元素,但是有些情况系统无法生成对应的HTML元素,它会产生一些附加的元素来完成用户想要的效果。
如下图:
上图种:div1、div2、div3,它们在一行,div4在下一行,它们并没有父类元素。
如果要这样排比较困难,可以将这4个div全部设置为flaot:left,如果这样,div3需要设置margin-right,让它填满右侧距离,这样div设置flaot:left时候才会换行。如果这四个元素它的父元素的宽度不确定,那么我们就没有办法来控制它的margin-right。
我们还可以将div4不设置为float:left,如果这样,div4会到div1的顶部去。为了保存div4的元素位置,可以更改它们的margin-top值。
我们这里的解决办法是将div1、div2、div3在它的外围创建一个TMP元素(div)。可以就这个三个div设置为flaot:left。div4就不需要设置为float样式。
脚本如下:
<div class="__tmp"> <span id="id"class="name"> </span> <div> </div> <div> </div> </div> <div> </div> body>div:nth-child(1){height:347px;} #id{width:262px;height:205px;margin-top:142px;margin-left:341px;float:left; background-color:#008000;} body>div:nth-child(1)>div:nth-child(2){width:210px;height:190px;margin-top:142px; margin-left:11px;float:left;background-color:#808000;} body>div:nth-child(1)>div:nth-child(3){width:375px;height:198px;margin-top:142px; margin-left:16px;float:left;background-color:#a6caf0;} body>div:nth-child(2){width:289px;height:187px;margin-top:74px; margin-left:341px;background-color:#808000;}