让一个元素始终在窗口水平、垂直位置居中

1、

div{
	width:200px;
	height:200px;
	background:#f00;
	position:fixed;
	left:0;
	right:0;
	top:0;
	bottom:0;
	margin:auto;
}

2、

div{
	width:200px;
	height:200px;
	background:#f00;
	position:absolute;
	left:50%;
	top:50%;
	margin:-100px 0 0 -100px;
} 
发布了12 篇原创文章 · 获赞 0 · 访问量 113

猜你喜欢

转载自blog.csdn.net/ZywOo_/article/details/104620949