热门关键字:
jquery > jquery教程 > jquery教程 > 使用absolute绝对定位,配合margin使用,实现水平垂直居中

使用absolute绝对定位,配合margin使用,实现水平垂直居中

521
作者:管理员
发布时间:2020/8/8 22:42:09
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=2337

相对应于relative的绝对定位absolute,需要定宽。同时,top/bottom应该相等,并且相加不超过定宽度。 right/left也应该相等,并且相加不超过定宽。

再配合margin: auto使用

<div class="parent-frame" style="position: relative">
 
 利用绝对定位,配合margin:auto自动计算外边距。
 
 <div class="child-frame" style="position: absolute; top: 0;right: 0; bottom: 0; left: 0;margin: auto;">
 
 定宽元素,需要确定的尺寸。relative是为了给子元素定位用。
 
 </div>
 
</div>

利用绝对定位,配合margin:auto自动计算外边距。 定宽元素,需要确定的尺寸。relative是为了给子元素定位用。





如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:DIV
友荐云推荐