CSS 垂直水平居中
CSS About 601 wordsabsolute + transform
<style>
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 200px;
height: 200px;
background-color: blue
}
</style>
<div class="center">
</div>
flex
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.element {
width: 200px;
height: 200px;
background-color: red;
}
</style>
<body>
<div class="element">
</div>
</body>
Views: 172 · Posted: 2025-09-06
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓

Loading...