【发布时间】:2012-11-10 06:40:26
【问题描述】:
我需要在表格单元格的顶角放置一个元素,并且文本应该堆叠在底部。我使用 vertical-align: bottom 将所有文本向下移动,但现在我遇到了顶部元素的问题,因为 table-cell 不支持相对定位......任何想法如何做到这一点?
<div style = "display: table-cell; vertical-align: bottom">
<div class = "top"> Top corner</div>
<h2> some text in the bottom </h2>
<h3> some more text in the bottom </h3>
</div>
编辑:它应该看起来像这样
+-----------+ +-----------+ +------------+
|top text | |top text | |top text |
| | | | | |
|some long | | | | |
|text | | | | |
|more long | | | | |
|text | | | | |
|end of | | | |some text |
|text | |text | |text |
|<button> | |<button> | |<button> |
+-----------+ +-----------+ +------------+
这一切都包含在一个带有 display:table 的 div 中。 我想在这里使用 display:table-cell 的原因是保持这些列的高度相同,并且仍然可以灵活地适应列中不同长度的文本。
【问题讨论】:
-
您能描述一下您希望它看起来多一点吗?你包装 div 是否应用了任何样式(内联样式除外)。有固定高度吗?您希望 .top div 位于哪个顶角?也许图像模型可能有助于获得一些好的答案。
-
你想要这样的东西吗? jsfiddle.net/Kse3g/1 只是不通过在 css 中使用显式高度来伪造结果?
-
无法加载该链接,抱歉!我在描述中添加了一个小“图片”:)
-
我认为这不可能在使用 display: table-cell 的父元素内有一个绝对定位的元素,具有动态灵活的高度。