html - 将两个 div 与所有设备的图像和文本对齐

标签 html css twitter-bootstrap-3

我有以下 HTML:

<div class = "container">
  <div class = "img">
    <img src = "http://icons.iconarchive.com/icons/danieledesantis/playstation-flat/512/playstation-cross-icon.png">
  </div>
  <div class = "text">
    <h1>
      Click to close your window.
    </h1>
  </div>
</div>

和 CSS:

.img {
  width: 30%;
  float: left;
}
.text {
  width: 70%:
  float: right;
}

我想将文本 div 与 img div 垂直对齐。我想保持灵活的高度所以我不能使用

display: table and display: table-cell;

我尝试在文本上使用 padding-top,但我无法让它适用于所有设备。

如何将文本 div 与 img div 对齐,以便文本始终位于图像的中间?

这是 jsfiddle:https://jsfiddle.net/whqL4fot/1/

最佳答案

开始使用 Flexbox :)

.container {
    -webkit-flex-direction: row; 
    flex-direction: row;
    -webkit-flex-wrap: nowrap;
    flex-wrap: nowrap;
    -ms-flex-align: center;
    -webkit-align-items: center;
    -webkit-box-align: center;
    align-items: center;
}

更新了 jsfiddle ( https://jsfiddle.net/whqL4fot/2/ )

关于html - 将两个 div 与所有设备的图像和文本对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36543811/

相关文章:

html - 如何使用 Bootstrap 将文本环绕图像?

javascript - HTML5 Canvas ;图像剪辑和多个图像

jquery - 可排序的元素拖动到其他 DOM 元素下方

css - 如何以给定 div 相对于其父 div 的百分比计算 padding-top

html - 根据 Bootstrap 中的设备隐藏和移动 div

html - 如何通过滚动在 bootstrap 中平滑地保留 div 100% 高度?

javascript - 在php中提交html表单

html - 如何选择包装的 HTML 元素?

html - 在此上下文中,元素 hr 不允许作为元素 ul 的子元素。 (抑制来自该子树的更多错误。)

css - 如何限制导航栏中 Bootstrap 3 下拉菜单的宽度