一、使用单元格居中

<!DOCTYPE html>
<html>
<head>
<title>测试</title>
</head>
<style type="text/css">
/* 使用单元格居中 */
.out {
width: 400px;
height: 400px;
background: pink;
display: table-cell;
        text-align: center;
vertical-align: middle;
}
.content {
width: 100px;
height: 100px;
display: inline-block;
background: coral;
} </style>
<body>
<div class="out">
<div class="content"> </div>
</div>
</body>
</html>

二、弹性盒子 flex

<!DOCTYPE html>
<html>
<head>
<title>测试</title>
</head>
<style type="text/css">
/* 使用弹性盒子 */
.out {
width: 400px;
height: 400px;
background: rgb(109, 106, 107);
display: flex;
}
.content {
width: 100px;
height: 100px;
display: inline-block;
background: coral;
margin: auto;
} </style> <body>
<div class="out">
<div class="content"> </div>
</div>
</body> </html>

三、使用transform移动定位

<!DOCTYPE html>
<html> <head>
<title>测试</title>
</head>
<style type="text/css">
/* 使用弹性盒子 */
.out {
width: 400px;
height: 400px;
background: powderblue;
position: relative;
}
.content {
width: 100px;
height: 100px;
background: coral;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
} </style> <body>
<div class="out">
<div class="content"> </div>
</div>
</body> </html>

四、margin-left、margin-top

<!DOCTYPE html>
<html> <head>
<title>测试</title>
</head>
<style type="text/css">
/* 使用弹性盒子 */
.out {
width: 400px;
height: 400px;
background: powderblue;
position: relative;
}
.content {
width: 100px;
height: 100px;
background: coral;
position: absolute;
margin-top: 50%;
margin-left: 50%;
} </style> <body>
<div class="out">
<div class="content"> </div>
</div>
</body> </html>

最新文章

  1. SSMS错误:A connection was successfully established with the server, but then an error occurred during the login process
  2. canvas画简单电路图
  3. OpenGL官方教程——着色器语言概述
  4. this对象
  5. HDU 2577(DP)
  6. HTML5中的Range对象的研究
  7. hadoop启动后jps没有namenode(转)
  8. C#使用EmguCV实现视频读取和播放,及多个视频一起播放的问题
  9. python安装(windows)
  10. 【原创】用python实现shell的tail操作
  11. applicationContext-mail.xml 模板
  12. IO 图
  13. 根据日期字符串获取星期几,日期获取星期,时间获取星期,js获取星期
  14. 简单的RPC java实现
  15. 【转】Android Application 对象介绍
  16. self-question
  17. 利用ASP.NET操作IIS (可以制作安装程序)
  18. NFS服务
  19. 多线程动态规划算法求解TSP(Traveling Salesman Problem) 并附C语言实现例程
  20. 13点值得我们注意的谷歌的JavaScript编写风格

热门文章

  1. XView 架构升级之路
  2. 工业仿真:Chai 3D之点云技术
  3. ThreadLocal最终版本
  4. Google Webstore Config
  5. Android 7.0+模拟器Fiddler抓包详细教程 fiddler443问题解决办法
  6. gitlab中CI/CD过程中的坑
  7. python 自动化 代码操作数据库
  8. Unity3D调用Android功能与组件(10.1):应用自启动
  9. Python条件语句和基本数据类型
  10. Asp.net中web.config配置文件最全面详解 (转载至CSDN)