移动端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 之类的即可. 主要麻烦的地方还是在垂 ...
随机推荐
- 20165214 2018-2019-2 《网络对抗技术》Exp4 恶意代码分析 Week6
<网络对抗技术>Exp3 免杀原理与实践 Week5 一.实验目标与内容 1.实践目标 1.1是监控你自己系统的运行状态,看有没有可疑的程序在运行. 1.2是分析一个恶意软件,就分析Exp ...
- 使用lua读文件并输出到stdin
io.input("c:\\AudioCom.log") t= io.read("*all") io.write(t) 三行代码搞定,简洁的不像话 io.rea ...
- 2019-04-18-day035-守护线程与池
内容回顾 互斥锁 在同一个进程中连续锁两次以上会死锁 进程的数据共享 进程之间可以共享数据 提供共享数据的类是Manager 但是他提供的list\dict这些数据类型是数据不安全的 针对 += -= ...
- SpringMVC后台接受前台传值的方法
1.HttpRequestServlet 接收前台传值 @RequestMapping("/go5") public String hello5(HttpServletReques ...
- servlet之小demo(四)
描述: 1.在web.xml文件中设置两个web应用的初始化参数,user和password 2.定义一个login.html,里面定义两个请求字段:user,password,发送请求到loginS ...
- Eureka的初识
在bili看完spring cloud eureka高可用注册中心的视频以后总结: 正常开发中,肯定有一个功能聚集服务中心,将功能方法全部写入其中,也就是一个springboot项目.该服务配置如下: ...
- html+jquery实现简单图片裁剪
有了上一篇图片放大镜的铺垫,今天的这个例子是缩小镜,因为裁剪的原图往往很大,不能在工作区域看到全部图片,所以,要有缩小镜来显示,当前裁剪的区域是原图的个部分.按照惯例首先看下效果图: 功能一:载入默认 ...
- 学习笔记:spark Streaming的入门
spark Streaming的入门 1.概述 spark streaming 是spark core api的一个扩展,可实现实时数据的可扩展,高吞吐量,容错流处理. 从上图可以看出,数据可以有很多 ...
- 在CMD命令下安装nexus报错和启动的问题
安装问题问题描述: 在控制台(cmd)下执行nexus install命令安装nexus服务的时候报错: wrapper | OpenSCManager failed - 拒绝访问. (0x5) 同时 ...
- reset()方法的使用、jq下面reset()的正确使用方法
reset()是 原生js的的方法,所有浏览器都支持,而且必须是form元素包括下的表单元素,但是JQuery中没有reset方法, 效果图: 错误用法: 正确用法: js用法: document. ...