CSS居中布局总结
居中布局
<div class=”parent”>
<div class=”child”>demo</div>
</div>
1.水平居中
1> 方案一 inlink-block+text-align
.child {display:inlink-block;}
.parent {text-align:center;}
优点:兼容性好
缺点:子元素宽高不可设置
2> 方案二 table+margin
.child {display:table; margin:0 auto;}
优点:只需要设置child(自己)
3> 方案三 absolute+transform
.parent {position:relative;}
.child {position:absolute;left:50%;transform:translateX(-50%);}
优点:子元素不会对其他元素产生影响
缺点:兼容性问题
4> 方案四 flex+justify-content
.parent {display:flex;justify-content:center;}
优点:只需设置parent节点
或者设置为
.parent {display:flex;}
.child {margin:0 auto;}
缺点:flex低版本ie不支持
2.垂直居中
1> 方案一 table-cell+vertical-align
.parent {display:table-cell;vertical-align:middle;}
优点:只需设置父节点,兼容性好
2> 方案二 absolute+transform
.parent {position:relative;}
.child {position:absolute;top:50%;transform:translateY(-50%);}
优点:子元素不会对其他元素产生影响
缺点:兼容性问题
3> 方案三 flex+align-items
.parent {display:flex;align-items:center;}
优点:只需设置父节点
缺点:兼容性问题
3.水平和垂直均居中
1> 方案一 inline-block+text-align+table-cell+vertical-align
.parent {text-align:center;display:table-cell;vertical-align:middle;}
.child {display:inline-block;}
2> 方案二 absolute+transform
.parent {position:relative;}
.child { position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);}
3> 方案三 flex+justify-content+align-items
.parent {display:flex;justify-content:center;align-items:center;}
本文转自:http://www.cnblogs.com/xiaohangzi/p/6090995.html
CSS居中布局总结的更多相关文章
- CSS居中布局方案
基本结构 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- CSS居中布局总结【转】
居中布局 <div class="parent"> <div class="child">demo</div> </d ...
- 详解 CSS 居中布局技巧
水平居中元素: 通用方法,元素的宽高未知 方式一:CSS3 transform .parent { position: relative; } .child { position: absolute; ...
- 详解CSS居中布局技巧
本文转自:https://zhuanlan.zhihu.com/p/25068655#showWechatShareTip一.水平居中元素: 1.通用方法,元素的宽高未知方式一:CSS3 transf ...
- CSS 居中布局
来源:http://www.cnblogs.com/QianBoy/p/8539077.html 水平居中 1)使用inline-block+text-align 原理:先将子框由块级元素改变为行内块 ...
- css居中布局的几种方式
一.水平居中 若是行内元素,则直接给其父元素设置text-align: center即可 若是块级元素,则直接给该元素设置margin: 0 auto即可 若子元素包含浮动元素,则给父元素设置widt ...
- CSS居中布局
一:水平居中方案: 1.行内元素 设置 text-align:center 2.定宽块状元素 设置 左右 margin 值为 auto 3.不定宽块状元素 a:在元素外加入 table 标签(完整的, ...
- css 居中布局方案
position(transform css3 有些浏览器不兼容) <article id="one"> <section id="section&q ...
- CSS基础布局--居中对齐,左侧定宽右侧自适应
CSS页面布局是web前端开发的最基本的技能,本文将介绍一些常见的布局方法,涉及到盒子布局,column布局,flex布局等内容.本文中,你可以看到一些水平垂直居中的方法,左侧固定宽度,右侧自适应的一 ...
随机推荐
- ubutu之mysql emma中文乱码问题解决
emma默认用apt-get 安装的话,emma是不支持中文的,配置文件或直接修改emma程序源文件(python).apt-get安装emmasudo apt-get install emma ...
- ajax读取XML文本(如读取城市)
//加载城市 function loadArea_pep() { $.ajax({ url: "/xmlFile/crty.xml", success: function (res ...
- webpack 教程 那些事儿03-webpack两大精华插件,热加载
本节主要讲述 webpack的两大经典开发调试插件,热插拔内存缓存机制 文章目录 1. html-webpack-plugin插件的使用 2. webpack-dev-middleware 插件登场 ...
- [codevs1027]姓名与ID
[codevs1027]姓名与ID 试题描述 有N个人,各自有一个姓名和ID(别名).每个人的姓名和ID都没有重复.这些人依次进入一间房间,然后可能会离开.过程中可以得到一些信息,告知在房间里的某个人 ...
- 160809225-叶桦汀《C语言程序设计》实验报告
#include<stdio.h> int main() { int a,b,c,t; printf("请输入三个整数"); scanf("%d%d%d&qu ...
- PHP环境搭建——Apache、Mysql、PHP单独安装(for Windows)
提示: 安装之前先要安装vcredist_x86.exe或vcredist_x64.exe(vc6,vc9,vc11等,和下面对应). 确保apache和php是用同样版本的编译器编译出来的,如果是v ...
- ubuntu14.04 server安装gnome-desktop
You can install the default Ubuntu desktop by executing the following: sudo apt-get install ubuntu-d ...
- vs2013 内置IIS Express相关问题
问题描述,以前做的程序迁移到vs2013后出现500.22问题. HTTP 错误 500.22 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设 ...
- 【leetcode】Word Search
Word Search Given a 2D board and a word, find if the word exists in the grid. The word can be constr ...
- 手动fsck修复
[转自]http://blog.chinaunix.net/uid-26719405-id-3781541.html 由于硬盘常年读写,系统会造成系统文件损坏,导致重启后无法登陆到系统, fsck不仅 ...