Html 属性“nowrap”被认为是过时的。建议使用较新的构造。它是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10446639/
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
Attribute 'nowrap' is considered outdated. A newer construct is recommended. What is it?
提问by Adil
I'm getting an error when compiling this within an ASPX page using Visual Studio 2010:
使用 Visual Studio 2010 在 ASPX 页面中编译时出现错误:
<td valign="top" nowrap width="237">
The error message is
错误信息是
"Attribute 'nowrap' is considered outdated. A newer construct is recommended."
What construct is the error message referring to? And does it behave exactly the same as 'nowrap'?
错误消息指的是什么结构?它的行为是否与“nowrap”完全相同?
回答by Adil
You can use it like this, I hope you wont get outdated message now.
你可以这样使用它,我希望你现在不会收到过时的消息。
<td valign="top" style="white-space:nowrap" width="237">
As pointed by @ThiefMaster it is recommended to put width
and valign to CSS (note: CSS calls it vertical-align
).
正如@ThiefMaster 所指出的,建议对width
CSS进行 put和 valign(注意:CSS 调用它vertical-align
)。
1)
1)
<td style="white-space:nowrap; width:237px; vertical-align:top;">
2)We can make a CSS class like this, it is more elegant way
2)我们可以像这样制作一个CSS类,这是更优雅的方式
In style section
在风格部分
.td-some-name
{
white-space:nowrap;
width:237px;
vertical-align:top;
}
In HTML section
在 HTML 部分
<td class="td-some-name">
回答by Jukka K. Korpela
There are several ways to try to prevent line breaks, and the phrase “a newer construct” might refer to more than one way—that's actually the most reasonable interpretation. They probably mostly think of the CSS declaration white-space:nowrap
and possibly the no-break space character. The different ways are notequivalent, far from that, both in theory and especially in practice, though in some given case, different ways might produce the same result.
有多种方法可以尝试防止换行,而“较新的构造”一词可能指代不止一种方式——这实际上是最合理的解释。他们可能主要想到的是 CSS 声明white-space:nowrap
,也可能是不间断空格字符。不同的方式并不等同,远非如此,无论是在理论上还是在实践中,尽管在某些给定的情况下,不同的方式可能会产生相同的结果。
There is probably nothing real to be gained by switching from the HTML attribute to the somewhat clumsier CSS way, and you would surely lose when style sheets are disabled. But even the nowrap
attribute does no work in all situations. In general, what works most widely is the nobr
markup, which has never made its way to any specifications but is alive and kicking: <td><nobr>...</nobr></td>
.
从 HTML 属性切换到有点笨拙的 CSS 方式可能没有什么真正的收获,而且当样式表被禁用时,你肯定会失败。但即使是该nowrap
属性也不适用于所有情况。一般来说,最广泛使用的是nobr
标记,它从未达到任何规范,但仍然活跃:<td><nobr>...</nobr></td>
.
回答by Mahib
If HTML and use bootstrap they have a helper class.
如果 HTML 并使用引导程序,则它们有一个辅助类。
<span class="text-nowrap">1-866-566-7233</span>
回答by Gerardo Lima
Although there's CSS defines a text-wrapproperty, it's not supported by any major browser, but maybe vastly supported white-spaceproperty solves your problem.
尽管有 CSS 定义了text-wrap属性,但它不受任何主要浏览器的支持,但也许广泛支持的white-space属性可以解决您的问题。