Attribute 'nowrap' is considered outdated. A newer construct is recommended. What is it?
Asked Answered
A

4

84

I'm getting an error when compiling this within an ASPX page using Visual Studio 2010:

    <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'?

Alishiaalisia answered 4/5, 2012 at 9:57 Comment(0)
H
142

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).

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

In style section

.td-some-name
{
  white-space:nowrap;
  width:237px;
  vertical-align:top;
}

In HTML section

<td class="td-some-name">
Hoodlum answered 4/5, 2012 at 10:4 Comment(4)
Why not move the width and valign into the CSS, too?Odyssey
Good suggestion let me do thatHoodlum
Consider changing "width" to "min-width:<anything>" so all empty table cells will be similarSpy
Thank you! I have been searching for this answer; style="white-space:nowrap" for over a month.Animalist
F
11

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 not equivalent, far from that, both in theory and especially in practice, though in some given case, different ways might produce the same result.

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>.

Fraser answered 4/5, 2012 at 11:12 Comment(5)
Using <nobr> breaks spec and is generally frowned upon. Not all browsers are guaranteed to support it. Wrapping control is a task for CSS by definition. More infoAlpenstock
@Zenexer, nobr is actually supported by all browsers. No browser is required to support CSS, and some actually don’t, at least in some circumstances. Since HTML has an element for forcing a line break, it is just logical that it has (as actually implemented) also an element for preventing line breaks.Fraser
Using <br> is generally frowned upon, too. ;)Alpenstock
@Alpenstock Is there any reference of why br is frowned upon?Housewifery
I guess this answer is just old, because it makes no sense to use nowrap attribute, which is officially deprecated in HTML5, rather than white-space:nowrap style when building a site now.Sloat
L
9

If HTML and use bootstrap they have a helper class.

<span class="text-nowrap">1-866-566-7233</span>
Leontine answered 25/5, 2017 at 17:45 Comment(0)
U
3

Although there's CSS defines a text-wrap property, it's not supported by any major browser, but maybe vastly supported white-space property solves your problem.

Ugrian answered 4/5, 2012 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.