简体   繁体   English

表格单元格内链接的垂直对齐底部

[英]Vertical align bottom for a link inside a table cell

Is it possible to push a link to the bottom of it's table cell without knowing the height of the table cell? 是否可以在不知道表格单元格高度的情况下将链接推到表格单元格的底部? Here's a fiddle I set up illustrating the problem: http://jsfiddle.net/77qG5/1/ I'd like the link with the red background to be aligned to the bottom of it's cell, but I can't put a fixed height on the cell due to other requirements. 我设置了一个小提琴来说明问题: http : //jsfiddle.net/77qG5/1/我希望红色背景的链接与单元格的底部对齐,但是我不能固定由于其他要求,电池的高度。 Here's the full code I'm using: 这是我正在使用的完整代码:

HTML: HTML:

<table>
    <tr>
        <td><div class="button"><a href="#">link text</a></div></td>
        <td>yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda</td>
    </tr>
</table>

And CSS: 和CSS:

.button { 
    display: table;
    background: red;
    height: 100%;
}
a {
    display: table-cell;    
    vertical-align: bottom;
}
td { 
    border: 1px solid #ccc;
    height: 100%;
}

One update: Ah, sorry. 一个更新:啊,对不起。 I should have said, we can't add vertical-alignment to the <td> because there will be other content in the cell that needs to be aligned at the top of the cell... We're trying to just target specific content in the cell but not all the content in the cell. 我应该说,我们不能在<td>添加垂直对齐方式,因为单元格中的其他内容需要在该单元格的顶部对齐...我们正在尝试仅针对特定内容单元格中的所有内容,但不是单元格中的所有内容。

Put vertical-align: bottom on the td containing the link vertical-align: bottom放在包含链接的td的vertical-align: bottom

edit for comment: 编辑评论:

How bout position: relative; position: relative; on the td, position: absolute; bottom: 0; 在td上, position: absolute; bottom: 0; position: absolute; bottom: 0; on .button? 在.button上? http://jsfiddle.net/77qG5/4/ http://jsfiddle.net/77qG5/4/

Added valign='bottom' in td 在td中添加了valign='bottom'

<table>
        <tr>
        <td valign="bottom"><div class="button"><a href="#">link text</a></div></td>
        <td >yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda</td>
        </tr>
    </table>

Demo: http://jsfiddle.net/77qG5/3/ 演示: http//jsfiddle.net/77qG5/3/

Replace your .button class with this.. Add .button class for td. 以此替换您的.button类。为td添加.button类。

td.button { 
    background: red;
    height: 100%;
    Vertical-align: bottom;
}

tdbutton { border: 1px solid #ccc; tdbutton {边框:1px实心#ccc; height: 100%; 高度:100%; vertical-align: bottom; 垂直对齐:底部; } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM