1 Star 0 Fork 0

计爱玲 / WebTest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
绝对定位和transform.html 784 Bytes
一键复制 编辑 原始数据 按行查看 历史
2604150210 提交于 2020-10-24 12:49 . 12种CSS垂直居中布局方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>使用绝对定位和transform</title>
<style>
#box {
width: 300px;
height: 300px;
background: #ddd;
position: relative;
}
#child {
background: orange;
position: absolute;
top: 50%;
transform: translate(0, -50%);
}
</style>
</head>
<body>
<h1>使用绝对定位和transform</h1>
<p>这种方法有一个明显的好处就是不必提前知道被居中元素的尺寸了,因为 transform 中 translate 偏移的百分比就是相对于元素自身的尺寸而言的。</p>
<div id="box">
<div id="child">test vertical align</div>
</div>
</body>
</html>
1
https://gitee.com/jiailing/WebTest.git
git@gitee.com:jiailing/WebTest.git
jiailing
WebTest
WebTest
master

搜索帮助