好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

css实现元素水平、垂直居中

在我们实际项目中,有很多关于 垂直居中 的方法,比如,在手机页面中有很多的 弹框提示 内容,简单整理如下,希望可以帮助到大家。
做了很多的页面,感觉垂直居中这个问题一直存在,感觉有的方法比较简单,有的却需要根据实际情况去算,我整理的是我在实际中使用过的方法,可能不是最全面的,但实操效果还是不错的哟。

废话少说直接上代码咯:

/* 常用的三种方法 */

/* 第一种 */
div{
	width: 200px;
	height: 200px;
	margin: auto;
	background: pink;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
}
/* 第二种 */
div{
	width: 200px;
	height: 200px;
	background: green;
	position: fixed;
	top: 50%;
	left: 50%;
	margin-left: -100px;
	margin-top: -100px;
}
/* 第三种 */
div{
	width: 200px;
	height: 200px;
	background: green;
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
} 

html部分直接去实现去套吧

相关推荐:

CSS控制滚动条样式的解析

CSS3自定义滚动条样式的示例详解

CSS设置div滚动条样式的示例

以上就是css实现元素水平、垂直居中的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于css实现元素水平、垂直居中的详细内容...

  阅读:45次