【问题标题】:Place text to the bottom instead of right below the other text将文本放在底部而不是其他文本的正下方
【发布时间】:2013-04-18 08:28:57
【问题描述】:

我正在使用不同的 DIV 标签来充当表格,我想在内容 DIV 的底部获取另一个 DIV。

<div class="table">
    <div class="table-row">

        <div class="table-information">
            Content
        </div>

        <div class="table-content">
            More content

            <div class="extra">
                Here's the extra content
            </div>
        </div>

    </div>
</div>

这是 CSS:

.table {
    display: table;
}

.table-row {
    display: table-row;
}

.table-information {
    background-color: #eaeaea;
    height: 150px;
    padding: 10px 15px;
    width: 150px;
}

.table-content {
    display: table-cell;
    height: 150px;
    padding: 10px 15px;
}

.extra {
    vertical-align: bottom
}

如您所见,vertical-align: bottom;extra 类。我希望将内容放在该 DIV 的底部,而不是文本 More content 的正下方。但是当我尝试这个解决方案时没有任何反应。

http://jsfiddle.net/edgren/3jjbV/

我该如何解决这个问题?

提前致谢。

【问题讨论】:

  • vertical-align: bottom 适用于.extra 的内容,而不是div 本身。
  • 好的。如何在table-content DIV 标签的底部制作 DIV 及其内容?

标签: css vertical-alignment


【解决方案1】:

这是实现这一目标的一种方法

.table-content {
    display: table-cell;
    height: 150px;
    padding: 10px 15px;
    position:relative;
    width:150px;
}
.extra {
    vertical-align: bottom;
    bottom:0;
    position:absolute;
}

我通过将相对位置添加到容器 table-content 然后绝对定位底部到 extra 来做到这一点。
这是fiddle


另一种方式是这样的:

.extra {
    vertical-align: bottom;
    display:table-cell;
    height: 150px;
    width:150px;
} 

这是第二个选项的fiddle
从这两个选项中,我个人会选择第一个, 但是你应该小心固定的宽度和高度(因为绝对定位)。

【讨论】:

  • 非常好!谢谢! :D 我会尽快接受你的回答。我会使用你的第一个解决方案,我会注意固定的高度和宽度:)
猜你喜欢
  • 1970-01-01
  • 2011-07-14
  • 1970-01-01
  • 2016-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-03
  • 2021-09-15
相关资源
最近更新 更多