解析四种常用方法以及原理:浮动、浮动内嵌 div、定位、flex。
浮动
<style type="text/css">
.wrap {background: #eee; padding: 20px; }
p {margin: 0; }
.left {width: 200px; height: 200px; float: left; background: coral; }
.right {width: 200px; height: 200px; float: right; background: lightblue; }
.middle {margin: 0 200px; background: lightpink; }
</style><div class="wrap">
<p class="left">我在左边</p>
<p class="right">我在右边</p>
<p class="middle">我排最后,但是跑到中间来了</p>
</div>

原理:
浮动元素和非浮动元素不在同一个立体空间,如果不清浮动,位置在它下面的元素将往上浮。
浮动元素高度为0,浮动盒子层级比
block 块级水平盒子高,比
inline/inline-block 水平盒子低。浮动内嵌 div
<style type="text/css">
.wrap {background: #eee; padding: 20px; }
p {margin: 0; }
.left {width: 200px; height: 200px; float: left; background: coral; margin-left: -100%;}
.right {width: 200px; height: 200px; float: left; background: lightblue; margin-left: -200px;}
.middle {width: 100%; height: 200px;float: left; background: lightpink; }
span{
display: inline-block;
margin: 0 200px;
}
</style><div class="wrap">
<p class="middle">
<span class="inner">
我在中间
</span>
</p>
<p class="left">我在左边</p>
<p class="right">我在右边</p>
</div>

原理:
三个元素都浮动,其中主题元素沾满一行 100% ,利用负
margin 把左右两边的元素放好。主题元素里面再套一个子元素,子元素
margin: 0 200px ,防止内容跑到左右两块浮动元素下面被遮盖。定位
<style type="text/css">
.wrap {background: #eee; position: relative;}
p {margin: 0; }
.left {width: 200px; height: 200px; background: coral; position: absolute;left: 0; top: 0;}
.right {width: 200px; height: 200px; background: lightblue; position: absolute;right: 0; top: 0;}










