使用 CSS 在表格单元格中右对齐
我有像这样的旧经典代码,
<td align="right">
它的作用如下:它正确对齐单元格中的内容。 因此,如果我在此单元格中放置两个按钮,它们将出现在单元格的正确位置。
我正在将其重构为 CSS,但似乎没有任何右对齐的内容。我看到text-align,但是是一样的吗?
I have the old classic code like this,
<td align="right">
which does what it says: it right aligns the content in the cell.
So if I put two buttons in this cell, they will appear at the right site of the cell.
I was refactoring this to CSS, but there doesn't seem to be anything as right align. I see text-align, but is it that the same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
请参阅
文本对齐
Use
See
text-align
不要忘记 CSS3 的“nth-child”选择器。如果您知道希望将文本右对齐的列的索引,则只需指定
在大型表的情况下,这可以为您节省大量额外的标记!
这是给你的小提琴...... https://jsfiddle.net/w16c2nad/
Don't forget about CSS3's 'nth-child' selector. If you know the index of the column you wish to align text to the right on, you can just specify
In cases with large tables this can save you a lot of extra markup!
here's a fiddle for ya.... https://jsfiddle.net/w16c2nad/
现在对我有用的是:
CSS:
HTML:
请参阅以下小提琴:
http:// /jsfiddle.net/Joysn/3u3SD/
What worked for me now is:
CSS:
HTML:
See the following fiddle:
http://jsfiddle.net/Joysn/3u3SD/
如何在 td 单元格中定位块元素
提供的答案对于在 td 单元格中右对齐文本非常有用。
当您希望按照接受的答案中的注释对齐块元素时,这可能不是解决方案。为了使用块元素实现这一点,我发现使用边距很有用;
一般语法
右对齐
How to position block elements in a
td
cellThe answers provided do a great job to right-align text in a
td
cell.This might not be the solution when you're looking to align a block element as commented in the accepted answer. To achieve such with a block element, I have found it useful to make use of margins;
General syntax
Justify right
Justify center
Align center
JSFiddle example
Alternatively, you could make you
td
content displayinline-block
if that's an option, but that may distort the position of its child elements.