方法1:

.parent {
width:800px;
height:500px;
border:2px solid #000;
position:relative;
}
.child {
width:200px;
height:200px;
margin: auto;
position: absolute;
top:; left:; bottom:; right:;
background-color: red;
}

方法2:

.parent {
width:800px;
height:500px;
border:2px solid #000;
display:table-cell;
vertical-align:middle;
text-align: center;
}
.child {
width:200px;
height:200px;
display:inline-block;
background-color: red;
}

方法3:

.parent {
width:800px;
height:500px;
border:2px solid #000;
display:flex;
justify-content:center;
align-items:center;
}
.child {
width:200px;
height:200px;
background-color: red;
}

方法4:

.parent {
width:800px;
height:500px;
border:2px solid #000;
position:relative;
}
.child {
width:300px;
height:200px;
margin:auto;
position:absolute;/*设定水平和垂直偏移父元素的50%,再根据实际长度将子元素上左挪回一半大小*/
left:50%;
top:50%;
margin-left: -150px;
margin-top:-100px;
background-color: red;
}

最新文章

  1. ios7 tableview被navigationbar挡住
  2. XML解析之SAX详解
  3. systemd
  4. Iframe跨域_ASP.NET
  5. 20160314 Servlet 入门
  6. CentOS在线升级内核
  7. 八、VueJs 填坑日记之参数传递及内容页面的开发
  8. Python——匿名函数
  9. js canvas游戏初级demo-上下左右移动
  10. ajax查看详细返回信息
  11. 安装stress模拟linux系统资源消耗
  12. [Android实例] Android Studio插件-自动根据布局生成Activity等代码1.4 (开源)(申明:来源于网络)
  13. Windows操作系统下Redis服务安装图文详解
  14. Android SDK的安装与环境配置
  15. 【vue】npm run mock & npm run dev 无法同时运行的解决
  16. Codeforces Round #296 (Div. 2) B. Error Correct System
  17. proxy-target-class 作用
  18. [pixhawk笔记]3-架构概览
  19. LeetCode -- Sum Root to Leaf NNumbers
  20. Mysql闪回工具之binlog2sql的原理及其使用

热门文章

  1. Coding 如何使用 Coding 开发 Coding
  2. 6.JBoss5.x6.x 反序列化漏洞(CVE-2017-12149)复现
  3. 5.docker的疑难杂症
  4. 如何解决Failed to start component [StandardEngine[Catalina].StandardHost[127.0.0.1].StandardContext[]]问题
  5. Ubuntu16.4下安装Chrome浏览器以及Chromedriver
  6. OpenStack基础知识-virtualenv工具详解
  7. 浅谈JavaScript--闭包
  8. oracle分页计算公式
  9. spring boot jpa 使用<S extends T> List<S> findAll(Example<S> example)查询数据
  10. 牛客 PUBG