css中垂直水平居中的方式有哪些 CSS之垂直水平居中的背后
最开始,我想说,这个体系有点大,我写的并不好。就当作是一个思路吧,虽然这个思路有点乱。几乎每一个实现方案的背后都是该属性及其组合的原理,每一个都要剖析其规范细节的话,这篇文章绝不会是这样的篇幅,所以每
顺晟科技
2021-09-21 13:16:05
230
<div class="fater"> <div class="sum"></div> </div>
<style> .fater{ width: 500px; height: 500px; border: 1px solid black; position: relative; } .sum{ width: 100px; height: 100px; background: red; position: absolute; left: 50%; top: 50%; margin-left: -50px; margin-top: -50px; } </style>
<style> .fater{ width: 500px; height: 500px; border: 1px solid black; position: relative; } .sum{ width: 100px; height: 100px; background: red; position: absolute; left: 50%; top: 50%; transform: translate(-50%); } </style>
<style> .fater{ width: 500px; height: 500px; border: 1px solid black; position: relative; } .sum{ width: 100px; height: 100px; background: red; position: absolute; left: 0; top: 0; right: 0; bottom: 0; margin: auto; } </style>
<style> .fater{ width: 500px; height: 500px; border: 1px solid black; display: flex; align-items: center; justify-content: center; } .sum{ width: 100px; height: 100px; background: red; } </style>
19
2022-10
15
2022-10
15
2022-09
15
2022-09
15
2022-09
14
2022-09