移动端css水平垂直居中
水平垂直居中
1.margin 负值调整偏移实现
兼容性: 当前流行的使用方法。
<div class="box">
<div class="content"></div>
</div>
.box{
width: 100%;
height: 100%;
}
.content{
position: absolute;
left: 50%;
top: 50%;
margin-left:-50px;
margin-top:-50px;
/* transform: translate(-50%,-50%);*/
height:100px;/* height的一半 */
width:100px; /*width的一半 */
background: pink;
}
首先设置绝对定位元素,相对于原点left,top设置50%。由于是基于content元素的开始位置,真正居中,需要设置content的中心点 水平垂直居中。
2.margin auto 实现
兼容性:IE7及之前版本不支持
<div class="box">
<div class="content"></div>
</div>
/* margin:auto */
.box{
position: relative;/* 非static定位 */ width: 200px;
height: 200px;
border: 1px solid;
}
.content{
position:absolute;/* 相对于父元素第一个非static定位 */
margin:auto;
top:;
left:;
right:;
bottom:; height:100px;
width:100px;
background: pink;
}
要点:绝对定位,margin:auto, TRBL 。
2.flex 实现
兼容性:css3特性
<div class="box">
<div class="content"></div>
</div>
.box{
display: flex;
justify-content: center;
align-items: center;
width: 200px;
height: 200px;
border: 1px solid;
}
.content {
width: 100px;
height: 100px;
background: pink;
}
设置容器使用flex布局,justify-content 设置主轴居中(水平居中),align-items 设置垂直居中。
4)table-cell 实现
<div class="box">
<div class="content"></div>
</div>
.box{
display: table-cell;
text-align: center;
vertical-align: middle;
width: 200px;
height: 200px;
border: 1px solid;
}
.content{
display: inline-block;
height:100px;
width:100px;
background: pink;
}
table-cell 布局,把内容水平居中和垂直居中。
移动端css水平垂直居中的更多相关文章
- CSS水平垂直居中总结
行内元素水平居中 把行内元素包裹在块级父元素中,且父元素中的css设置text-align:center; <!DOCTYPE html> <html> <head> ...
- HTML+CSS水平垂直居中
啦啦啦,好了,今天来分享自己的第一个知识点,难得自己还能想起来过来博客园,写写博客的. 好了,言归正传,今天分享关于html和css的一个简单的知识点,对于大部分从事前端开发的人员来说可能都是很简单的 ...
- css水平垂直居中对齐方式
1.文字或者内联元素的垂直水平居中对齐 css属性 -- 水平居中:text-aligin:center; 垂直居中: line-height:height; 例子:. html: <div c ...
- 把简单做好也不简单-css水平垂直居中
44年前我们把人送上月球,但在CSS中我们仍然不能很好实现水平垂直居中. 作者:Icarus 原文链接:http://xdlrt.github.io/2016/12/15/2016-12-15 水平垂 ...
- CSS水平垂直居中的方法
原文链接:http://caibaojian.com/370.html 水平垂直居中,特别是使用在列表的时候经常会用到的,以前有需求的时候我也做过类似的代码,是使用display:table-cell ...
- css 水平垂直居中总结
空闲总结了下水平垂直居中方案,欢迎补充: 水平居中 水平居中有两种情况: 子元素是内联元素 这种那个情况下只需要在父元素定义: text-align:center; 例子: html: //省略了bo ...
- CSS水平垂直居中的几种方法2
直接进入主题! 一.脱离文档流元素的居中 方法一:margin:auto法 CSS代码: div{ width: 400px; height: 400px; position: relative; b ...
- CSS水平垂直居中的几种方法
直接进入主题! 一.脱离文档流元素的居中 方法一:margin:auto法 CSS代码: div{ width: 400px; height: 400px; position: relative; b ...
- 常见的几种 CSS 水平垂直居中解决办法
用CSS实现元素的水平居中,比较简单,可以设置text-align center,或者设置 margin-left:auto; margin-right:auto 之类的即可. 主要麻烦的地方还是在垂 ...
随机推荐
- https加密流程
引用其它博主博客,在这里谢谢这位博主,原博客地址:https://blog.csdn.net/xincai/article/details/51954468 1,下面,用一幅图展示一下https建立 ...
- org.hibernate.AssertionFailure: null id in xxx entry (don't flush the Session after an exception occurs)
网上找了很久,发现造成原因有很多种,后来终于发现了端倪:看提示是发生了异常,查看业务代码,发现有这个逻辑:先插入记录,如果有唯一键约束异常(并发造成),catch时查询已存在的记录,查询的时候就报了此 ...
- 学习小片段——springboot 错误处理
一:先看看springboot默认的错误处理机制 springboot默认会判断是否是浏览器(http请求头Accept是否含有 text/html)来选择返回html错误页面或json错误信息 原因 ...
- Where do I belong (freeCodeCamp)
先给数组排序,然后找到指定的值在数组的位置,最后返回位置对应的索引. 举例:where([1,2,3,4], 1.5) 应该返回 1.因为1.5插入到数组[1,2,3,4]后变成[1,1.5,2,3, ...
- Archlinux安装指南~小米笔记本Air 13.3英寸版本
小米笔记本Air 13.3英寸版本,配置为:Intel Core i5-6200U处理器.8GB内存.256GB固态硬盘.NVIDIA GeForce 940MX独立显卡,13.3英寸1920X108 ...
- vue-router+elelment-ui,实现导航栏激活高亮
<el-menu :default-active="$route.path" class="el-menu-vertical-demo" backgrou ...
- 【Linux】scp指令
语法: scp [可选参数] file_source file_target 参数说明: -1: 强制scp命令使用协议ssh1 -2: 强制scp命令使用协议ssh2 -4: 强制scp命令只使用I ...
- 【EMV L2】Cardholder Verification Rule(CVR) Format
Cardholder Verification Rule(CVR)由两个字节组成: 高字节为Cardholder Verification Method (CVM) Codes,表示执行Cardhol ...
- blueprint的使用
第一步:导入蓝图模块: from flask import Blueprint 第二步:创建蓝图对象: #Blueprint必须指定两个参数,admin表示蓝图的名称,__name__表示蓝图所在模块 ...
- 常用的JSP内置对象(1)
常用的JSP内置对象 request对象主要用于处理客户端请求 request对象的作用是与客户端交互,收集客户端的Form.Cookies.超链接,或者收集服务器端的环境变量. request对象常 ...