热门关键字:
jquery > jquery教程 > jquery教程 > 使用absolute绝对定位,配合margin的负值(negative margins)来实现水平垂直居中

使用absolute绝对定位,配合margin的负值(negative margins)来实现水平垂直居中

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

negative margins负边距,会使结构塌陷,利用这个特点来实现。

<div class="parent-frame" style="position: relative;">
 
 利用绝对定位,配合margin的负值来实现居中。
 
 <div class="child-frame" style="position: absolute; top: 50%; left: 50%; margin-top: -51px; margin-left: -51px;">
 
 负边距来实现,水平垂直居中。需要知道该元素的具体大小
 
 </div>
 
</div>

利用绝对定位,配合margin的负值来实现居中。 负边距来实现,水平垂直居中。需要知道该元素的具体大小

html中div使用CSS实现水平/垂直居中的多种方式




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



关键字:div
友荐云推荐