【问题标题】:align header text vertically next to an image在图像旁边垂直对齐标题文本
【发布时间】:2016-09-08 14:45:04
【问题描述】:

我正在尝试垂直对齐图像旁边的标题文本。我的问题是当我减小窗口宽度并且文本换行(高度高于图像高度)时,它开始与图像顶部对齐

.half {
  width: 50%;
}
h4 {
  font-size: 40px;
}
<div class="half">
  <div class="advantages_header">
    <img class="advantages_icon" src="http://placehold.it/90x90" />
    <h4>HEADER TEXT MAYBE LONG</h4>
  </div>
</div>

【问题讨论】:

  • 需要更多解释。根据我的理解,如果您为媒体查询编写 css 将解决您的问题。

标签: css alignment text-alignment


【解决方案1】:

哦!我自己想出来的,感谢阅读,希望对大家有帮助:)

.half {
  width: 50%;
}
.advantages_header {
  position: relative;
  height: 90px;
}
h4 {
  left: 110px;
  margin-right: 110px;
  font-size: 40px;
  position: relative;
  top: 50%;
  transform: translate(0, -50%);
}
img {
  position: absolute;
  top: 50%;
  transform: translate(0, -50%);
}
<div class="half">
  <div class="advantages_header">
    <img class="advantages_icon" src="http://placehold.it/90x90" />
    <h4>HEADER TEXT MAYBE LONG</h4>
  </div>
</div>

【讨论】: