元素水平垂直居中的三种方式

时间:5年前   阅读:3731

第1种水平垂直居中的方法

.dd{    
				width: 400px;    
				height: 300px;    
				background: darkcyan;    
				/*第一种水平垂直居中的方法*/    
				position: fixed;    
				left: 50%;    
				top: 50%;    
				margin-left:-200px;    
				margin-top: -130px;    
			}


<div class="dd"></div>

第2种水平垂直居中的方法


.dd{    
				width: 400px;    
				position: fixed;    
				background: darkcyan;    
				/*如果元素没有固定的宽高*/    
				left: 50%;    
				top: 50%;    
				transform: translate(-50%,-50%);  /*translate 元素水平垂直*/    
			}


<div class="dd">李盈莹作为奇兵用可以,但作为中坚尚有距离,主要是稳定性差,关键战役失一个球就是1分,所以中美之战还没让之首发。而昨天首发的几个人几乎完美,丁霞的二传发挥到了极至,昨天一传不到位时大调整攻,中国的比美国下球还好,这朱婷最大的突破。</div>


第3种水平垂直居中的方法

.dd{    
				width: 400px;    
				height: 300px;    
				background: darkcyan;    
				/*第一种水平垂直居中的方法*/    
				position: fixed;    
				left: 0;    
				top: 0;    
				right: 0;    
				bottom: 0;    
				margin: auto;    
			}
<div class="dd"></div>

本站声明:网站内容来源于网络,如有侵权,请联系我们https://www.qiquanji.com,我们将及时处理。

微信扫码关注

更新实时通知

上一篇:css实现无滚动条的滚动方法

下一篇:如何控制沪深300期权投资中的亏损?

网友评论

请先 登录 再评论,若不是会员请先 注册