简体   繁体   English

垂直对齐:文本顶部; 不在HTML5中的表格单元格(td)中工作

[英]vertical-align:text-top; not working in table cell (td) in HTML5

Not sure why but for the life of me I cannot get my text to align on the top of a table cell (td) when the cell before it is wrapping text. 不知道为什么但是对于我的生活,当它前面的单元格包装文本时,我不能让我的文本在表格单元格(td)的顶部对齐。

If I write it out in the HTML it works, but unable to get the same effect in my CSS. 如果我在HTML中写出它可以工作,但无法在我的CSS中获得相同的效果。

Works with HTML: 适用于HTML:

<td style="vertical-align:text-top;">Some Text</td>

Doesn't with CSS: 没有CSS:

table td { vertical-align: text-top; }

And I have tried every combination you can think of within my CSS 我已经尝试过在CSS中可以想到的所有组合

Make sure you are not setting "display: block" on the TD elements, as vertical align doesn't work on block elements. 确保没有在TD元素上设置“display:block”,因为垂直对齐对块元素不起作用。 Also, text-top is not the best, and has some cross browser issues. 此外,text-top不是最好的,并且有一些跨浏览器问题。 Use "top" instead. 请改用“top”。 Try adding this in your stylesheet: 尝试在样式表中添加:

table td { 
  display: table-cell;
  vertical-align: top; 
}

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

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