微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

语义 – 跨度的语义价值

跨度元素似乎完全像一个div,而是在线级而不是块级.然而,我似乎不能想到跨元素可以提供的任何有益的逻辑划分.

一句话或一句话,如果不包含在句子中,似乎是最小的逻辑部分.忽略CSS,因为CSS仅用于布局而不是语义意义上,跨越提供额外的语义值时,通过剔除一个句子或一串字呢?

似乎在所有情况下,其他元素更适合于添加语义值,使跨越一个纯布局元素.这是真的?

解决方法

Span可以用来添加超出 HTML范围的语义.这可以通过使用识别某些属性的类来完成.例如,如果您正在撰写科幻小说,您可以使用span来识别组合词,因为您可能希望格式化格式不同,或者您可能希望拼写检查器忽略它们:

Then the wizard called upon the <span class=”wizardword”>gravenwist</span> and bade it attack the approaching army. The <span class=”wizardword”>gavenwist</span> resisted but the wizard’s <span class=”wizardword”>wistwand</span> was too powerful.

这可以渲染为

Then the wizard called upon the gravenwist and bade it attack the approaching army. The gavenwist resisted but the wizard’s wistwand was too powerful.

这种事情的另一个很好的例子是microformats,它允许在HTML内创建任意结构:

<span class="tel">
 <span class="type">home</span>:
 <span class="value">+1.415.555.1212</span>
</span>

跨度与div的优点在于,跨度可以出现在几乎所有地方,因为它们是内联内容,而div是块元素,因此它们只能发生在某些其他元素内.

原文地址:https://www.jb51.cc/html/230332.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐