html - 什么时候最好使用 HTML 表示标签或 CSS 来设计元素?

标签 html css underline

关闭。这个问题是opinion-based .它目前不接受答案。












想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题.

去年关闭。




Improve this question




通过在 HTML 和 CSS 中使用 class="pro"来使用这种方法有什么区别。

<p>a <u>pro</u>grammar</p> 
在 HTML 中?
HTML 使用类...
<p>a <span class="pro">pro</span>programmer.</p>
CSS类
.pro {text-decoration: underline;}
结果是一样的,但我想知道是否有理由为什么我应该使用一个而不是另一个。

最佳答案

<u>标签

The HTML Unarticulated Annotation element (<u>) represents a span of inline text which should be rendered in a way that indicates that it has a non-textual annotation. This is rendered by default as a simple solid underline, but may be altered using CSS.


避免使用 <u>
非语义下划线

To underline text without implying any semantic meaning, use a <span> element with the text-decoration property set to "underline".


注意:

Along with other pure styling elements, the original HTML Underline () element was deprecated in HTML 4; however, <u> was restored in HTML 5 with a new, semantic, meaning: to mark text as having some form of non-textual annotation applied.


重要提示:-

Be careful to avoid using the <u> element with its default styling (of underlined text) in such a way as to be confused with a hyperlink, which is also underlined by default.

<span>标签

The HTML <span> element is a generic inline container for phrasing content, which does not inherently represent anything.



.pro {text-decoration: underline;}
<p>a <u>pro</u>grammar</p> 
<p>a <span class="pro">pro</span>programmer.</p>

关于html - 什么时候最好使用 HTML 表示标签或 CSS 来设计元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64021034/

相关文章:

php - 在简单网站上缓存字体以防止 FOIT?

css - 除了标题幻灯片之外,如何在 RMarkdowns 的 ioslides 中放置 Logo ?

javascript - 使用 jquery 的选择器

css - 不确定如何从 css 中的图像中删除下划线

javascript - JS代码有什么问题,让我知道代码是否可以改进

jquery - 访问网站时运行自定义 javascript

javascript - 一起压缩 CSS、JS 和 HTML

html - <p> 标签字体大小未按预期工作

css - 自定义下划线

html - 在 CSS 中扩展下划线