我们经常用margin:0 auto来实现水平居中,而一直认为margin:auto不能实现垂直居中……实际上,实现垂直居中仅需要声明元素高度和下面的CSS:
.Absolute-Center {
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
最近使用了这个效果,转载于:
https://www.cnblogs.com/doseoer/p/4581284.html
这篇博客揭示了一个鲜为人知的CSS技巧,通过设置`margin:auto`和`position:absolute`,可以实现元素的垂直居中。示例代码`.Absolute-Center`展示了如何将元素在容器中垂直和水平居中。这种方法打破了对`margin:auto`仅用于水平居中的传统认知,为网页布局提供了新的解决方案。
我们经常用margin:0 auto来实现水平居中,而一直认为margin:auto不能实现垂直居中……实际上,实现垂直居中仅需要声明元素高度和下面的CSS:
.Absolute-Center {
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
最近使用了这个效果,转载于:
https://www.cnblogs.com/doseoer/p/4581284.html
9142
491

被折叠的 条评论
为什么被折叠?