一般地,居中绝对定位元素,left:50%;top:50%;再margin负值或者通过transform也可达到效果。
今天发现另一个技巧,利用,top,left,right,bottom取值0,再magin:auto,即可实现居中。
原因:
<div class='box>
<div class='jz'></div>
</div>div.box{
position: relative;
height: 300px;
background: #989eaa;
}
div.fz{
width: 100px;
height: 100px;
background: #499682;
position: absolute;
top:0;
left: 0;
right: 0;
bottom: 0;
margin:auto;
}更多css篇之absolute绝对定位元素居中技巧相关文章请关注PHP中文网!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号