方法一:.element { position: relative; top: 50%; transform: translateY(-50%);}
方法二:
HTML:
<body>
<div class="a1">
<div class="a2"></div>
</div>
</body>
css:
.a1{width: 100%;height: 500px;display: table-cell;text-align: center;vertical-align: middle; }
.a2 { width:50px; height:50px; background:green;display: table; }
时间: 2024-10-19 13:09:10