1.采用负边距和position结合方式
<html> <head></head> <body> <style type="text/css"> .big{ position:relative;background:#eee; width:100%;height:100%; } .small{ position:absolute;top:50%;left:50%; width:200px;height:200px;border:1px solid red; margin:-100px 0 0 -100px;background:#fff; } </style> <div class="big"> <div class="small">盒子居中</div> </div> </boyd> </html>
时间: 2024-11-05 22:49:19