css 定位元素上下左右居中

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>	
    <style>
        *{margin:0;padding:0;}  
		.box{
			width:300px;height:100px;background:red;
			position:fixed;
			left:0px;
			right:0px;
			top:0px;
			bottom:0px;
			margin:auto;
		}
    </style>
</head>
<body>	
    <div class="box"></div>
    
</body>
</html>

发布了100 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Misnice/article/details/104514315