Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div class="parent">
    <div class="child">
      未知高度的块级元素;当垂直居中的元素的高度和宽度未知时,我们可以借助CSS3中的transform属性向Y轴反向偏移50%的方法实现垂直居中,但是部分浏览器存在兼容性的问题。
    </div>
  </div>
</body>
</html>
 
.parent {
  border: 1px solid red;
  position: relative;
  height: 200px;
}
.child {
  border: 1px solid blue;
  position: absolute;
  transform: translateY(-50%);
  top: 50%;
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers