Element “align” is obsolete or non-standard: what should I use instead?

梦想与她 提交于 2019-12-05 09:04:13

问题


I have this HTML code:

<td align="center">

and I'm getting this error in Visual Studio 2008 from ReSharper:

"Element 'align' is obsolete or nonstandard"

What is the replacement of this code to make it standard?


回答1:


You should use text-align in CSS rather than using the obsolete html styling attributes.

td{
text-align:center;
}



回答2:


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.




回答3:


You did not explain your goal, but using CSS is more modern...

<td style="text-align: center;">

Using that within a stylesheet, rather than inline would be even better...

td {
    text-align: center;
}



回答4:


Use CSS, not element attributes.

<td style="text-align: center;">

You can also place this in an external style sheet:

td {
    text-align: center;
}



回答5:


use css styling:

text-align:center

but styling tables doesn't really work well on ie6, if you need it




回答6:


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.




回答7:


Maybe with CSS?

text-align:center



回答8:


#1 search result on Google for replacing deprecated 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.

<h1 style="text-align: center;width: 100%">



来源:https://stackoverflow.com/questions/7108504/element-align-is-obsolete-or-non-standard-what-should-i-use-instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!