<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>垂直居中 ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>垂直居中</title>
<style>
.parent{width: 400px;height: 400px;border:1px solid grey;display: }
.children{width: 200px;height: 200px;background-color: #ccc;}
/*table-cell*/
.parent{display: table-cell;text-align: center;vertical-align: middle;}
.children{display: inline-block;}
/*flex*/
.parent{display: flex;justify-content: center;align-items: center;}
/*position transform*/
.parent{position: relative;}
.children{position: absolute;top:50%;left: 50%;transform:translate(-50%,-50%);}
/*position margin 不推荐使用,使用必须设置宽高*/
.parent{position: relative;}
.children{position: absolute;top:0;left: 0;bottom: 0;right: 0;margin: auto;}
</style>
</head>
<body>
<div >
<div >
</div>
</div>
</body>
</html>
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:css垂直居中的四种方法
关键词:CSS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。