【问题标题】:Vertically align multiple lines of text in a div [duplicate]垂直对齐div中的多行文本[重复]
【发布时间】:2017-04-26 11:39:57
【问题描述】:

我目前正在编写一个 RSS 解析器,我使用 Ractive 来生成视图。我正在尝试根据 .feed-item 的高度垂直对齐 .feed-text-offset 的内容。

我怎样才能做到这一点?

演示:https://jsfiddle.net/zzx5L4e9/

输出的 HTML 是这样的:

<div class="feed-item">
    <div class="news-img-container">
        <img class="news-thumbnail" src="#" style="max-width: 125px;">
    </div>
    <div class="feed-text-offset">
        <a href="#" target="_blank">Text here</a>
        <span class="feed-item-since">1 hr</span></div>
        <div style="clear: both;">
    </div>
</div>

CSS

.feed-item {
    padding: 2px;
    background-color: green;
    float:left;
}

.feed-item-since {
    font-size: 0.8em;
    font-weight: 400;
    margin-top: 5px;
    display: block;
}

.news-img-container {
    width: 125px;
    float: left;
}

.feed-text-offset {
    margin-left: 130px;
}

【问题讨论】:

标签: html css


【解决方案1】:

https://stackoverflow.com/a/31078418/969894 找到我的答案并感谢@GCyrillus

我可以将以下内容应用于 .feed-item 并重新调整文本偏移以垂直对齐 .feed-text-offset 的内容

display: flex;
align-items: center;

【讨论】:

  • 当您在另一个问题的答案中找到解决方案时,您不应该发布答案,您应该投票将其作为重复项关闭
猜你喜欢
  • 2012-03-04
  • 2018-10-24
  • 2012-12-09
  • 2017-01-17
  • 2021-07-29
  • 1970-01-01
  • 2017-03-03
  • 2018-10-29
  • 2014-05-01
相关资源
最近更新 更多