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">
    <span class="child">
      给父元素添加100%高度的伪元素before、after,让文本和伪元素垂直对齐,从而达到垂直居中的目的
    </span>
  </div>
</body>
</html>
 
.parent {
  border: 1px solid red;
  height: 200px;
  text-align: center;
}
.child {
  border: 1px solid blue;
  display: inline-block;
  width: 300px;
  height: 100px;
  vertical-align: middle;
}
.parent::before {
  content: '';
  height: 100%;
  display: inline-block;
  vertical-align: middle;
}
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers