Why is the deprecated?

后端 未结 7 865
生来不讨喜
生来不讨喜 2021-02-04 23:34

I understand that this tag could easily be replaced with and a little bit of CSS, but in real life markup I often find that <

相关标签:
7条回答
  • 2021-02-05 00:17

    It isn't deprecated because it was never standard in the first place.

    HTML is (in theory) a semantic markup language. It describes the structure and semantics of a document along with relationships to other resources.

    HTML is not supposed to describe presentation. A bunch of presentational features were added during the browser wars. Some of these became standardised. Most of them were subsequently deprecated when CSS came along.

    CSS is a language for describing presentation. When you have a chunk of text that shouldn't have a line break in it, that is usually a matter of presentation so CSS is the right place to do it.

    The exceptions are usually handled by non-breaking spaces (&nbsp;).

    0 讨论(0)
  • 2021-02-05 00:17

    I found this interesting and very explaining comment on a w3c mailing list:

    <NOBR> cannot be deprecated as it has never been part of even transitional W3C HTML versions; it is purely proprietory.

    Yep. So it never was and never will be part of the spec. Just something 'missing' added using CSS.

    0 讨论(0)
  • 2021-02-05 00:19

    Feel free to use the obsolete/non-standard <nobr> HTML tag — so long as you define it in CSS.

    It's virtually guaranteed that this element name will never be repurposed for any task other than its original behavior, and this name is descriptive of the action you'll define in CSS, making it intuitive for people reviewing your HTML.

    ⚠  Custom elements (including obsolete elements) will make your code fail to validate as HTML.

    Your CSS will need to look like this:

    nobr  {  white-space: nowrap;  hyphens: none;  }
    

    You may or may not want (or need) the hyphens: none; part, but I have added it for completeness since it appears some implementations of <nobr> (used to?) also suppress hyphenation while white-space: nowrap; does not do that.

    This defines the white-space as nowrap, which suppresses line breaks within white space and the hyphens as none, which prevents breaking within words (including ignoring characters within words that "suggest line break points").

    0 讨论(0)
  • 2021-02-05 00:19

    The proper way to achieve what you want is to declare that "V. V. Putin" is a proper noun, and define in CSS that such a proper noun should not be line breaked.

    <span class="propernoun">V. V. Putin</span>
    

    and in CSS you would define

    .propernoun {
      white-space: nowrap;
    }
    

    Since... HTML is not about style, it is about content. Basically, this is the same as what the OP suggested, but the nowrap in class="nowrap" describes a presentational property in html which should be in the stylesheet.

    0 讨论(0)
  • 2021-02-05 00:29

    That's because a proper tag should be semantically useful, when <nobr> doesn't have any semantics apart from its style. I guess that's the same reason why <center> and similar styling tags were deprecated.

    0 讨论(0)
  • 2021-02-05 00:32

    As said, names shall not be breaked, due Russian typography: Thus there is some semantics. So as You said Yourself, instead of marking the name by <nobr>..</nobr> formatting tags, let's use meaningful <person>..</person> tags. And voilà, you can style the name as needed, i.e. by white-space: nowrap; rule for all pages, or for just the Russian localization.

    0 讨论(0)
提交回复
热议问题