Html 元素“align”已过时或非标准:我应该使用什么来代替?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7108504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Element "align" is obsolete or non-standard: what should I use instead?
提问by hotcoder
I have this HTML code:
我有这个 HTML 代码:
<td align="center">
and I'm getting this error in Visual Studio 2008 from ReSharper:
我在 Visual Studio 2008 中从 ReSharper 收到此错误:
"Element '
align
' is obsolete or nonstandard"
“元素 '
align
' 已过时或非标准”
What is the replacement of this code to make it standard?
什么是替换此代码以使其成为标准?
回答by Jamie Dixon
You should use text-align
in CSS rather than using the obsolete html styling attributes.
您应该text-align
在 CSS 中使用,而不是使用过时的 html 样式属性。
td{
text-align:center;
}
回答by jeroen
That would be something like:
那将是这样的:
<td style="text-align: center;">
But it would be even better to move that style out of the html and put it in a separate style-sheet.
但是最好将该样式从 html 中移出并将其放在单独的样式表中。
回答by Sparky
You did not explain your goal, but using CSS is more modern...
你没有解释你的目标,但使用 CSS 更现代......
<td style="text-align: center;">
Using that within a stylesheet, rather than inline would be even better...
在样式表中使用它,而不是内联会更好......
td {
text-align: center;
}
回答by Terrik
Use CSS, not element attributes.
使用 CSS,而不是元素属性。
<td style="text-align: center;">
You can also place this in an external style sheet:
你也可以把它放在一个外部样式表中:
td {
text-align: center;
}
回答by Einacio
use css styling:
使用 css 样式:
text-align:center
but styling tables doesn't really work well on ie6, if you need it
但是如果需要,样式表在 ie6 上并不能很好地工作
回答by Nathan Q
Maybe with CSS?
也许用CSS?
text-align:center
回答by oliver-clare
You could try using <td style="text-align: center;">
. However, table elements themselves are not really recommended, so it might be Visual Studio's way of trying to force you to use the <div>
element.
您可以尝试使用<td style="text-align: center;">
. 但是,实际上并不推荐表格元素本身,因此它可能是 Visual Studio 试图强制您使用该<div>
元素的方式。
回答by solbs
#1 search result on Google for replacing deprecated align="center"
.
替换已弃用的align="center"
.
For people like me looking for ways to center other elements (not just <td>
) you may also need to add width: 100%
to the style tag.
对于像我这样正在寻找使其他元素(不仅仅是<td>
)居中的方法的人,您可能还需要添加width: 100%
到样式标签中。
<h1 style="text-align: center;width: 100%">
<h1 style="text-align: center;width: 100%">