<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> <style type="text/css"> .test_center { background-color:Red; width:500px; height:300px; position: absolute;/*设置为绝对定位*/ top: 50%; left:50%; margin-left:-250px;/*设置为宽度的一半*/ margin-top:-150px;/*设置为高度的一半*/ } </style> </head> <body> <div class="test_center"> </div> </body> </html>
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)