Html 使用 <u>underline</u> 是否已弃用且未经验证?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2110779/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:56:22  来源:igfitidea点击:

Is use of <u>underline</u> deprecated and non validated?

htmlxhtmlw3c

提问by Jitendra Vyas

Is use of underline deprecated and non validated?

下划线的使用是否已弃用且未经验证?

回答by Jonny Haynes

It's deprecated in HTML 4 http://www.w3.org/TR/REC-html40/present/graphics.html#edef-Uso won't validate.

它在 HTML 4 http://www.w3.org/TR/REC-html40/present/graphics.html#edef-U 中已弃用,因此不会进行验证。

Use styles instead. Maybe a <span>tag. Although, if you want the thing you're trying to add an underline to, to be emphasized without styles enabled. Use an <em>tag and use CSS to give it an underline.

改用样式。也许是一个<span>标签。虽然,如果您想要在不启用样式的情况下强调要添加下划线的内容。使用<em>标签并使用 CSS 为其添加下划线。

回答by Sampson

Yes, it's deprecated. Use styles instead. Note also that underlined text can be confusing, as it resembles the default styling of links, and might frustrate some users.

是的,它已被弃用。改用样式。另请注意,带下划线的文本可能会令人困惑,因为它类似于链接的默认样式,并且可能会让某些用户感到沮丧。

If you wanted, you could even repurpose another HTML element, like em:

如果您愿意,您甚至可以重新利用另一个 HTML 元素,例如em

CSS:

CSS:

em {
  font-style: normal;         /* Removes italics */
  text-decoration: underline; /* Makes underline */
}

HTML:

HTML:

<p>I like to <em>underline</em> words.</p>

回答by Jay

<rant>

<咆哮>

General comment on "semantics versus style": While there is certainly truth to this, it is a lesson that some people have way way overlearned.

关于“语义与风格”的一般评论:虽然这肯定是事实,但有些人已经过度学习了这一教训。

In real life, many people use italics for emphasis. Sure, I could create a CSS style of "span.emphasized { font-style: italic;}", and then instead of putting "<i></i>" around the emphasized text, put "<span class='emphasized'></span>". And exactly what does that gain, besides a lot of extra typing?

在现实生活中,很多人使用斜体来强调。当然,我可以创建一个 CSS 样式“span.emphasized { font-style: italic;}”,然后在强调的文本周围放置“<i></i>”,而是放置“<span class='emphasized '></span>”。除了大量的额外输入之外,这究竟有什么好处?

Further, there are a million reasons why I might want to put a piece of text in, say, italics. Perhaps it is the title of a book; perhaps I want to emphasize it; perhaps I am using the convention of italicizing foreign words; etc. If I have 10 words in a document that are italicized for 9 different reasons, the pedantic answer is that I should create 9 different CSS style entries to describe all these reasons. Personally, I almost never do this, because it gains nothing. Yes, theoretically I might decide that book titles should be in a cursive font instead of italicized or some such. In practice, the probability that this will happen is pretty close to zero, and if it did, and I have two such book titles in my document, I can just change it twice. Theoretically someone might want to scan my text with a program that looks for book titles. But in practice, unless we have arranged this in advance and we have agreed on the CSS class names, there is no way they are going to do this.

此外,我可能想要将一段文本放入斜体的原因有一百万个。也许这是一本书的书名;也许我想强调一下;也许我在使用外来词斜体的惯例;等等。如果我在一个文档中有 10 个单词由于 9 个不同的原因被斜体,那么迂腐的答案是我应该创建 9 个不同的 CSS 样式条目来描述所有这些原因。就我个人而言,我几乎从不这样做,因为它没有任何好处。是的,理论上我可能会决定书名应该使用草书字体而不是斜体或类似字体。实际上,这种情况发生的概率非常接近于零,如果确实如此,而且我的文档中有两本这样的书名,我只需将其更改两次即可。从理论上讲,有人可能想使用查找书名的程序来扫描我的文本。

I'm not saying CSS is useless. Quite the contrary. When I have a semantic object that is repeated many times in my text, and which has no "natural", widely-recognized style, it then becomes quite plausible to suppose that as I continue to work on the document I may want to change the style. In that case it is much easier to change a single CSS entry than to change a hundred instances. Or I may want to use a different style in different situations, like put warning messages in red when displaying on the screen but put them in bold when printing a black-and-white document.

我并不是说 CSS 没用。恰恰相反。当我有一个语义对象在我的文本中重复多次,并且没有“自然”的、广泛认可的风格时,那么假设当我继续处理文档时,我可能想要更改风格。在这种情况下,更改单个 CSS 条目比更改一百个实例要容易得多。或者我可能想在不同的情况下使用不同的样式,例如在屏幕上显示时将警告消息显示为红色,而在打印黑白文档时将它们显示为粗体。

For exmample, I routinely use CSS for quote citations because I often change my mind about italicizing, indenting, and font size. I never use CSS for text that I want italicized for emphasis because I know it is extremely unlikely that I will ever want to render this as anything other than italics.

例如,我经常使用 CSS 来引用引用,因为我经常改变对斜体、缩进和字体大小的看法。我从不将 CSS 用于我想用斜体来强调的文本,因为我知道我极不可能将它呈现为斜体以外的任何内容。

My point is, I don't care that some pedant said "This is a rule that you must always obey. You ask why you must obey it? But I just told you! Because it's a rule!" I use tools and techniques that are useful in the present application. (And yes, yes, there are lots of rules of thumb that are valid 99% of the time and aren't worth thinking about until the rare exception turns up.)

我的意思是,我不在乎某些学究说“这是你必须始终遵守的规则。你问为什么必须遵守它?但我只是告诉你!因为这是规则!” 我使用在当前应用程序中有用的工具和技术。(是的,是的,有很多经验法则在 99% 的情况下都是有效的,并且在罕见的例外出现之前不值得考虑。)

</rant>

</rant>

回答by LBushkin

The <u>tag has been deprecated in favor of stylesheets.

<u>标签已被弃用,取而代之的是样式表。

Most browsers will continue to recognize it for a long time to come, simply out of need to be backwards compatible with the content already out there. But if you want to by XHTML compliant, you should avoid using it.,

大多数浏览器会在很长一段时间内继续识别它,只是出于向后兼容已经存在的内容的需要。但是如果你想通过 XHTML 兼容,你应该避免使用它。,

You can read some more about deprecated HTML tags here.

您可以在此处阅读有关已弃用的 HTML 标记的更多信息。

回答by Joe Martinez

Yes, it was deprecated in HTML 4. However, you can just use the following css.

是的,它在 HTML 4 中已被弃用。但是,您可以只使用以下 css。

span.underline { text-decoration: underline; }

However, the underline class name is not semantic. You may want to replace it with a class name that describes the content you need underlined.

但是,下划线类名不是语义的。您可能希望将其替换为描述您需要加下划线的内容的类名。

回答by Buhake Sindi

The tag is deprecated but not obsolete. The reason it's not obsolete is to allow browsers to support the element for backward compatibility.

该标签已弃用但未过时。它没有过时的原因是允许浏览器支持该元素以实现向后兼容性。

The tag is not defined in the xhtml1-strict.dtdbut it's available under xhtml1-frameset.dtdand xhtml1-transitional.dtd. It's declaration are as follows (not on Strict DTD):

该标签未在xhtml1-strict.dtd 中定义,但在xhtml1-frameset.dtdxhtml1-transitional.dtd下可用。它的声明如下(不在 Strict DTD 上):

<!ELEMENT u %Inline;>   <!-- underline -->
<!ATTLIST u %attrs;>

This is to allow backward compatibility with browsers.

这是为了允许与浏览器的向后兼容。

Do notuse the tag as "This tag has been deprecated in favor of style sheets". It may soon become obsolete. Rather use stylesheet, e.g.

不要将标签用作“此标签已被弃用,以支持样式表”。它可能很快就会过时。而是使用样式表,例如

/** Underlining an anchor tag in CSS **/
a {
    text-decoration: underline;
}

回答by Peter Rowell

You tagged your question with both XHTML and HTML. the U tag is definitely deprecated in xhtml-strict. I think it may still be OK in HTML-4-Transitional. As other people have said, use styles instead. With good name they give more semantics to your docs.

您使用 XHTML 和 HTML 标记了您的问题。在 xhtml-strict 中绝对不推荐使用 U 标记。我认为在 HTML-4-Transitional 中它可能仍然可以。正如其他人所说,请改用样式。凭借良好的名称,它们为您的文档提供了更多的语义。

回答by aslum

If you're using the latest version of HTML or XHTML then yes it's deprecated. Regardless, in general you want to avoid underlining anything that isn't a link, as it can make things more confusing for the user.

如果您使用的是最新版本的 HTML 或 XHTML,那么是的,它已被弃用。无论如何,通常您希望避免在任何不是链接的内容下加下划线,因为它会使用户更加困惑。

回答by NotMe

Deprecated: yes.
Validated: ? I guess that depends on what you are using to validate it.

弃用:是的。
验证: ? 我想这取决于您用来验证它的内容。

http://www.codehelp.co.uk/html/deprecated.html

http://www.codehelp.co.uk/html/deprecated.html

回答by Dominik Sandjaja

Yes, it is deprecated.

是的,它已被弃用。