您的位置:首页 > 其它

div 水平居中的一种方法

2016-06-04 21:58 375 查看
<span style="font-size:24px;">水平居中的方法:</span>
<span style="font-size:24px;">1、parent float to left;</span>
<span style="font-size:24px;">2、parent  position 相对页面 右移50%,则父类div的做边界为page的中心轴;</span>
<span style="font-size:24px;">3、child  relative相对父类标签;</span>
<span style="font-size:24px;">4、child margin padding 0 则child的边界与parent重合,即可以理解为一个</span>
<span style="font-size:24px;">5、child left -50%右边界向左缩进50%,则child和parent就居中了;

</span>
.parent{float:left;position:relative;left:50%;}.parent .child{position:relative;margin:0;padding:0;left:-50%;}
<div class="parent"><div class="child">水平居中</div></div>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: