html结构:

    <div class="center">确定宽高水平垂直居中</div>
<div class="center2">不确定宽高水平垂直居中</div>
<div class="center3">确定宽高水平垂直居中2</div>
<div class="center4"><span>flex水平垂直居中</span></div>
<div class="center5"><span>table-cell水平垂直居中</span></div>

css样式:

    .center{
position: absolute;
background: blue;
width: 200px;
height: 200px;
text-align: center;
line-height: 200px;
left: 50%;
top: 50%;
margin-left: -100px;
margin-top: -100px;
}
.center2{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -150%);
background: red;
}
.center3{
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
margin: auto;
width: 100px;
height: 100px;
background: green;
}
.center4{
background: orange;
display: flex;
justify-content: center;
align-items: center;
height: 100px;
}
.center5{
display: table-cell;
vertical-align: middle;
text-align: center;
height: 300px;
width: 400px;
background: red;
}

PS:仅作记录.

最新文章

  1. php入门一ubuntu16.04中php环境配置及一个网页
  2. Linux进程间通信(五):信号量 semget()、semop()、semctl()
  3. iOS-----About Asset Catalog
  4. WinForm 窗体应用程序 (初步)之二
  5. 如何修改VPN连接的MTU,解决频繁断线和页面打不开的问题
  6. 【M35】让自己习惯于标准C++语言
  7. 【Knockout】五、创建自定义绑定
  8. 链表与Hash检索实测
  9. 正则表达式:网页爬虫:从TXT中获取邮箱地址(获取的练习,缺点:一行只能匹配一个)
  10. javascript类型转换、运算符、语句
  11. hibernate_@GeneratedValue
  12. Flutter环境搭建
  13. MySQL - exists与in的用法
  14. loading加载的代码
  15. ns3的输入输出奥秘(二) 命令行参数
  16. 下面属于javascript对象的有:( )
  17. Hbase 之 HBase 的整体架构
  18. PPTP
  19. mongodb查看数据库和表的信息
  20. 【DB2】判断连续时间,如果间断则新增一条记录

热门文章

  1. Kafka基础教程(一):认识Kafka
  2. CAS学习笔记三:SpringBoot自动配置与手动配置过滤器方式集成CAS客户端
  3. mysql语句3-插入、修改删除表
  4. Module 4 - Azure SQL
  5. nuxt2.0项目创建(最新)
  6. C语言 生成一个随机数
  7. 快速搭建Hadoop-Hive-Zoopkeeper-Sqoop环境进入Sqoop学习环境
  8. vue特效网站集锦
  9. Amazon EKS 中 EFS 持久性存储
  10. hisql orm update表数据更新文档