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">
      固定高度的块级元素; 如果我们知道居中元素的高度和宽度, 可以通过绝对定位元素距离顶部50%,并设置margin-top向上偏移元素高度的一半,就可以实现垂直居中了。
    </div>
  </div>
</body>
</html>
 
.parent {
  border: 1px solid red;
  position: relative;
  height: 300px;
}
.child {
  border: 1px solid red;
  position: absolute;
  height:200px;
  top: 50%;
  margin-top: -100px;
}
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers