使用父div垂直对齐多行

时间:2018-05-12 14:16:19

标签: html css css3 flexbox centering

如何对齐中间div以使两条线垂直居中?

.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.second {
  text-align: left;
  flex-grow: 2;
}
img {
  margin-right: 20px;
}
<div class="container">
  <div>
    <img src="http://via.placeholder.com/75x75">
  </div>
  <div class="second">
   <h2>Please vertically center both</h2>
   <p>of us!</p>
  </div>
  <div>
   Right
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

添加Global Variable以移除为h2,p{margin:0}h2代码

提供的默认保证金

p
.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.second {
  text-align: left;
  flex-grow: 2;
}

img {
  margin-right: 20px;
}
h2,p{margin:0}