Why is the deprecated?

后端 未结 7 947
生来不讨喜
生来不讨喜 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:19

    Feel free to use the obsolete/non-standard 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 (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").

提交回复
热议问题