html:
<html> <head></head> <body> <div class="parent"> <div class="child"></div> </div> </body> </html>
css:
<style> .parent{ position:relative; width:600px; height:300px; border:1px solid red; } .child{ position:absolute; width:450px; height:198px; left:50%; top:50%; margin-left:-225px; margin-top:-99px; } </style>
效果如下图:
时间: 2024-11-12 06:29:09