你的位置:首页 > 软件开发 > 网页设计 > 居中的几种方法

居中的几种方法

发布时间:2017-10-30 12:00:37
一:通过margin负值.one{ position: absolute; width: 200px; height: 200px; top: 50%; left: 50%; margin-left: -100px;}兼容性好,但是必须要定宽高二:通过margin:auto.tw ...

一:通过margin负值

.one{ position: absolute; width: 200px; height: 200px; top: 50%; left: 50%; margin-left: -100px;}

兼容性好,但是必须要定宽高

二:通过margin:auto

.two{ position: absolute; width: 200px; height:200px; margin: auto 0;}

以上两种方法都可以把absolute换成fixed,注意,fixed在ie下不支持

三:行内元素居中

.three{ width: 100px; height: 100px; line-height: 100px; text-align: center;}

这种方法只能居中行内元素。常用于文字对其居中

四:transform居中

.four{ position: absolute; top: 50%; height: 50%; transform: translate(-50%, -50%);}

存在css3浏览器兼容问题

五:flex布局

.five{ display: flex; align-items: center; justify-content: center;}

存在css3浏览器兼容问题

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:居中的几种方法

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录