方法1:【绝对定位50%-本身50%】
             position:absolute; left:50%; top:50%;
             transform: translate(-50%,-50%); 
.div1{
width:400px;
height:400px;
border:#CCC 1px solid;
background:#99f;
position:absolute; left:50%; top:50%;/*绝对定位*/
transform: translate(-50%,-50%);
/*translate(x,y) 括号的百分比数据,会以本身的长宽做参考,比如,本身的长为100px,高为100px. 那填(50%,50%)就是向右,向下移动50px,添加负号就是向着相反的方向移动*/
} <div class="div1"></div>
方法2:不太懂

 .div2{
width:400px;
height:400px;
border:#CCC 1px solid;
background:#99f;
position: absolute;
left:0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
}
<div class="div2"></div>
方法3:【绝对定位50%-本身50%】

 .div3{
    width:400px;
    height:400px;
    border:#CCC 1px solid;
    background:#9f9;
    position: absolute;
    left: 50%;
    top:50%;
    margin-left:-200px;
    margin-top: -200px;
}
<div class="div3"></div>

  

最新文章

  1. 在Unity中使用UGUI修改Mesh绘制几何图形
  2. [.NET领域驱动设计实战系列]专题一:前期准备之EF CodeFirst
  3. iOS常用手势识别器
  4. Fliwer:监控植物状态 实现远程浇水
  5. ios 学习总结之动画(转)
  6. ZooKeeper典型应用场景一览
  7. studio--如何将Eclipse中的项目迁移到Android Studio 中
  8. C:指针
  9. centos 安装git server
  10. 复制表的sql语句
  11. [HTML5] Input accepts only 6 number characters
  12. 系统调用和中断处理的异同(以Linux MIPS为例)
  13. JavaScript详解
  14. scrapy使用PhantomJS爬取数据
  15. JAVA中正则表达式总结
  16. htop的安装和使用
  17. bzoj 4621: Tc605 动态规划
  18. leetcode-algorithms-34 Find First and Last Position of Element in Sorted Array
  19. Chapter 3 Phenomenon——16
  20. 【Coursera】支持向量机

热门文章

  1. webpack构建篇
  2. mocha单元测试简易教程
  3. 【2019.09.19】数独(Sudoku)游戏之我见(软工实践第三次作业)
  4. Invalid bound statement (not found) 错误原因
  5. [转]无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
  6. 共线性图 | Alluvial Diagrams | Parallel plot | Parallel Coordinates Plot
  7. python 代码性能分析 库
  8. Cucumber介绍
  9. IntelliJ IDEA添加JavaDOC注释 方法 快捷键
  10. Component &#39;TABCTL32.OCX&#39;错误的处理方法