这些 HTML 标签你一定从未使用过

简介: 这些 HTML 标签你一定从未使用过

HTML中有超过100个元素,所有这些元素都可以应用于文本片段,以赋予它们在文档中的特殊意义。我们大多数人只知道几个元素,比如<p>、<div>和<body>元素……

但是实际上还有很多隐藏在W3C参考的黑暗领域中。

< abbr > — 缩写

这个元素表示缩写(如Corporation➟Corp.)首字母缩写(如级联样式表➟CSS)。此外,可以使用它的title属性来编写单词的完整形式,以便屏幕阅读器可以阅读它,用户可以将鼠标悬停在上面阅读它。

<p>You can use <abbr title="Cascading Style Sheets">CSS</abbr> to style your <abbr title="HyperText Markup Language">HTML</abbr>.</p>

< ins > and < del > — 插入和删除

<ins><del>元素表示已添加或删除到文档中的文本范围。

<p>“You're late!”</p>
<del>
    <p>“I apologize for the delay.”</p>
</del>
<ins cite="../howtobeawizard.html" datetime="2018-05">
    <p>“A wizard is never late …”</p>
</ins>
<blockquote>
    There is <del>nothing</del> <ins>no code</ins> either good or bad, but <del>thinking</del> <ins>running it</ins> makes it so.
</blockquote>

< dfn >, < var >, < kbd >, < samp >, < output >

这些元素表示文档中特殊的面向技术的部分,比如定义、变量、击键等……

<p>A <dfn id="def-validator">validator</dfn> is a program that checks for syntax errors in code or documents.</p>
<p>The volume of a box is <var>l</var> × <var>w</var> × <var>h</var>, where <var>l</var> represents the length, <var>w</var> the width and <var>h</var> the height of the box.</p>

< bdo > 文本方向

此元素可以更改文本的方向,使其向后呈现。你可以使用dir属性控制它的行为。

虽然不是它的预期用途,但它可以使用HTML来反转文本!

<h1>Famous seaside songs</h1>
<p>The English song "Oh I do like to be beside the seaside"</p>
<p>Looks like this in Hebrew: <span dir="rtl">אה, אני אוהב להיות ליד חוף הים</span></p>
<p>In the computer's memory, this is stored as <bdo dir="ltr">אה, אני אוהב להיות ליד חוף הים</bdo></p>

< mark > 高亮文本

这个元素的目的是像使用标记一样突出显示文本。

<p>Search results for "salamander":</p>
<hr>
<p>Several species of <mark>salamander</mark> inhabit the temperate rainforest of the Pacific Northwest.</p>
<p>Most <mark>salamander</mark>s are nocturnal, and hunt for insects, worms, and other small creatures.</p>

< area > 可点击的图像区域

你可以使用此元素使图像的某些区域表现为链接!

<map name="infographic">
    <area shape="rect" coords="184,6,253,27"
          href="https://mozilla.org"
          target="_blank" alt="Mozilla" />
    <area shape="circle" coords="130,136,60"
          href="https://developer.mozilla.org/"
          target="_blank" alt="MDN" />
    <area shape="poly" coords="130,6,253,96,223,106,130,39"
          href="https://developer.mozilla.org/docs/Web/Guide/Graphics"
          target="_blank" alt="Graphics" />
    <area shape="poly" coords="253,96,207,241,189,217,223,103"
          href="https://developer.mozilla.org/docs/Web/HTML"
          target="_blank" alt="HTML" />
    <area shape="poly" coords="207,241,54,241,72,217,189,217"
          href="https://developer.mozilla.org/docs/Web/JavaScript"
          target="_blank" alt="JavaScript" />
    <area shape="poly" coords="54,241,6,97,36,107,72,217"
          href="https://developer.mozilla.org/docs/Web/API"
          target="_blank" alt="Web APIs" />
    <area shape="poly" coords="6,97,130,6,130,39,36,107"
          href="https://developer.mozilla.org/docs/Web/CSS"
          target="_blank" alt="CSS" />
</map>
<img usemap="#infographic" src="/media/examples/mdn-info.png" alt="MDN infographic" />

< dl >, < dd > 和 < dt > 描述性列表

可以使用这些元素创建语义准确的描述列表,其中在一个文本块中定义多个术语。

< sup > 和 < sub > 上标和下标

有了这两个元素,可以在文档中添加上标(如)和下标(如x₀)。

< figure > 和 < figcaption > 可附标题内容元素

你可以使用<figure>来包含想要的任何元素,例如图像。然后,添加<figcaption>作为它的最后一个子元素,可以添加一个文本块来描述上面的内容。

<figure>
    <img src="/media/cc0-images/elephant-660-480.jpg"
         alt="Elephant at sunset">
    <figcaption>An elephant at sunset</figcaption>
</figure>

< progress > 和 < meter > 进度条标记

这两个标签允许你创建语义正确的进度条元素,用来显示动作完成的距离。

<label for="file">File progress:</label>
<progress id="file" max="100" value="70"> 70% </progress>
<label for="fuel">Fuel level:</label>
<meter id="fuel"
       min="0" max="100"
       low="33" high="66" optimum="80"
       value="50">
    at 50/100
</meter>

< details > 可展开菜单

你可以使用此元素创建一个具有标题并可以使用按钮展开的本地菜单。不需要JavaScript。

<details>
    <summary>Details</summary>
    Something small enough to escape casual notice.
</details>

< dialog > 弹出对话框

使用这个元素可以创建语义准确的对话。它本身做不了多少事情,所以您必须使用CSS和JavaScript添加更多的功能。

<dialog open>
  <p>Greetings, one and all!</p>
  <form method="dialog">
    <button>OK</button>
  </form>
</dialog>

< datalist > -文本输入建议

这个元素允许你手动添加文本输入建议。你可以添加任何你想要的东西!

<label for="ice-cream-choice">Choose a flavor:</label>
<input list="ice-cream-flavors" id="ice-cream-choice" name="ice-cream-choice" />
<datalist id="ice-cream-flavors">
    <option value="Chocolate">
    <option value="Coconut">
    <option value="Mint">
    <option value="Strawberry">
    <option value="Vanilla">
</datalist>

< fieldset > -分组表单元素

使用<fieldset>元素保持表单整洁和用户友好。

<form>
  <fieldset>
    <legend>Choose your favorite monster</legend>
    <input type="radio" id="kraken" name="monster">
    <label for="kraken">Kraken</label><br/>
    <input type="radio" id="sasquatch" name="monster">
    <label for="sasquatch">Sasquatch</label><br/>
    <input type="radio" id="mothman" name="monster">
    <label for="mothman">Mothman</label>
  </fieldset>
</form>

< object > -嵌入外部对象

有了这个惊人的元素,你可以嵌入几乎任何你想要的文件到你的网站!最常用的支持文件是pdf、“爱腾优”视频等。

<object type="application/pdf"
    data="/media/examples/In-CC0.pdf"
    width="250"
    height="200">
</object>

< noscript >—如果JavaScript被禁用显示

当JavaScript被浏览器禁用时,这个元素可以用来显示一些内容。它通常被那些严重依赖JavaScript的网站所使用,比如单页应用程序(spa)。

<noscript>
  <!-- anchor linking to external file -->
  <a href="https://www.mozilla.com/">External Link</a>
</noscript>
<p>Rocks!</p>

如果你发现这个指南很有用,请不要忘记点赞👍🏻和在看哦!

我每天都会发这样的帖子,所以请关注我,了解更多信息。❤️



相关文章
|
25天前
|
移动开发 IDE 前端开发
HTML基础-标签与元素:构建网页的基石
【6月更文挑战第1天】HTML是网页基础,由标签和元素定义内容结构与样式。本文介绍HTML标签(如`<p>`)和元素(包括开始、结束标签及内容),并列出常见错误:忘记闭合标签、错误嵌套顺序、不恰当使用自封闭标签及混淆标签与属性。建议遵循标准、使用IDE辅助、验证代码和持续实践来避免错误。示例代码展示基本用法:`<html><head><title>...</title></head><body>...</body></html>`。学习HTML标签与元素是前端开发入门关键。
|
12天前
|
存储 JavaScript 前端开发
HTML标签data-属性的作用
HTML标签data-属性的作用
|
12天前
|
移动开发 HTML5 前端开发
【网页搭建基石】:揭秘HTML标签的魔法世界
【网页搭建基石】:揭秘HTML标签的魔法世界
|
21天前
|
数据采集 移动开发 搜索推荐
HTML基础-HTML5新增语义标签:解锁网页结构新维度
【6月更文挑战第5天】本文介绍了HTML5的语义标签,旨在提升网页结构化和可访问性。核心语义标签包括`&lt;header&gt;`、`&lt;nav&gt;`、`&lt;main&gt;`、`&lt;article&gt;`、`&lt;section&gt;`、`&lt;aside&gt;`、`&lt;footer&gt;`、`&lt;figure&gt;`和`&lt;figcaption&gt;`。常见问题包括滥用标签作布局工具、忽略`&lt;main&gt;`、不恰当嵌套和忽视辅助功能。
|
20天前
|
Web App开发 移动开发 前端开发
Web网页制作-知识点(3)——HTML5新增标签、CSS简介、CSS的引入方式、选择器、字体属性、背景属性、表格属性、关系选择器 二
Web网页制作-知识点(3)——HTML5新增标签、CSS简介、CSS的引入方式、选择器、字体属性、背景属性、表格属性、关系选择器 二
22 1
|
20天前
|
移动开发 前端开发 HTML5
Web网页制作-知识点(3)——HTML5新增标签、CSS简介、CSS的引入方式、选择器、字体属性、背景属性、表格属性、关系选择器一
Web网页制作-知识点(3)——HTML5新增标签、CSS简介、CSS的引入方式、选择器、字体属性、背景属性、表格属性、关系选择器 一
29 1
|
1天前
|
移动开发 前端开发 搜索推荐
HTML5飞跃指南:基础标签元素,网页设计的第一步
HTML5飞跃指南:基础标签元素,网页设计的第一步
|
1天前
|
前端开发
常用 HTML 标签元素(表格、表单)
常用 HTML 标签元素(表格、表单)
|
25天前
|
前端开发 搜索推荐 UED
HTML基础-文本格式化标签:美化网页内容
【6月更文挑战第1天】本文介绍了HTML的文本格式化标签,包括`<b>`、`<strong>`、`<i>`、`<em>`、`<u>`、`<s>`、`<mark>`、`<small>`、`<sub>`和`<sup>`等,强调了语义化使用和避免常见错误的重要性。示例代码展示了这些标签的用法,帮助提升网页内容的可读性和吸引力。
|
28天前
|
前端开发 JavaScript
HTML图像标签的深入解析与应用
HTML图像标签的深入解析与应用
22 1