水平居中的五种方法及其优缺点
来源:互联网 发布:手机mac地址是什么 编辑:程序博客网 时间:2024/05/17 08:02
<div class="parent"><div class="child">test</div></div>
第一种:
.parent{text-align: center;}.child{ display: inline-block;}优点:代码少,兼容性好 inline-block ie6-7不兼容(可用inline+zooom:1)
缺点:text-align 会将文字移动,有时需text-align:left解决;
第二种:
.child{display: table;margin: 0 auto;}优点:兼容性好 IE8及以上,不影响父元素
缺点:IE6-7不支持(需将HTML变为table结构)
第三种:
.parent{position: relative;}.child{position: absolute;left: 50%;transform: translate(-50%);}
优点:不定宽
缺点: 兼容性不好
第四种:
.parent{display: flex;justify-content: center;}
优点:简洁
缺点:兼容性不好
第五种:
.parent{display: flex;}.child{ margin:0 auto;}
优点:简洁
缺点:兼容性不好
阅读全文
1 0
- 水平居中的五种方法及其优缺点
- 水平垂直居中的方法及其优缺点
- 垂直居中的三种方法及其优缺点
- div垂直水平居中的五种方法
- 实现水平垂直居中的五种方法
- CSS水平居中的几种方法
- 水平垂直居中的几种方法
- 水平垂直居中的几种方法
- 7种元素的水平居中和垂直居中方法
- div盒子水平居中垂直居中的几种方法
- css 水平居中的方法
- div水平居中的方法
- css水平居中的方法
- 元素居中的三种方法(包括垂直居中和水平居中)
- 已知宽度的DIV水平居中的3种方法
- 元素的水平垂直居中的4种方法
- 元素的垂直水平居中的三种方法
- 图片垂直水平居中的N种方法
- 基于多核升级和自适应融合的改进的显著性检测(Improving Saliency Detection Via Multiple Kernel Boosting and Adaptive Fusion)
- 盗梦空间
- 重载
- Android中ContentProvider组件详解
- div 写的table form表单 easyui 弹窗
- 水平居中的五种方法及其优缺点
- 改写caffe classification.cpp使其支持批量读取图片
- jsonp详解跨域请求
- 项目提示 Cannot change version of project facet Dynamic Web Module to 2.5 错误
- 204Count Primes
- mac上命令行的快捷键和vim的快捷键
- 文件的上传+下载+表单的重复提交问题 +自定义拦截器:
- 在hive中虚构dual表
- JSP操作XML