html - caption(table) 和 legend(fieldset) 是唯一的 html first descendant 限制吗?

标签 html

<legend>, if used, must immediately follow <fieldset>
<caption>, if used, must immediately follow <table>

HTML 中还有其他类似“必须是第一个后代”的限制吗? (在没有阅读每个标签的完整规则的情况下,您是否可以在某个地方找到此类信息?) [主要关心 html5]

最佳答案

您可以在其他地方使用它们,但例如。 legend 为 Fieldset 上的标题提供了独特的样式,如果您错过了它,它将无法正常工作同样 caption 对表格有一些特定的含义。

这些只是预定义的标准。

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.container {
  width: 80%;
  margin: 0 auto;
}
legend {
  padding: 2px;
  color: purple
}
fieldset {
  margin-bottom: 10px;
  padding: 5px 10px;
  border: 2px solid #000;
}
input {
  width: 100%;
  padding: 5px 15px;
}
<div class="container">
  <fieldset>
    <legend>Heading inside Legend</legend>
    <input type="text">
  </fieldset>

  <table border="1" cellspacing="0" style="width:100%;">
    <caption>Caption inside Table</caption>
    <tr>
      <td>a</td>
      <td>a</td>
      <td>a</td>
      <td>a</td>
      <td>a</td>
    </tr>
    <tr>
      <td>b</td>
      <td>b</td>
      <td>b</td>
      <td>c</td>
      <td>d</td>
    </tr>
  </table>
</div>

关于html - caption(table) 和 legend(fieldset) 是唯一的 html first descendant 限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33238713/

相关文章:

html - 我应该只为不同尺寸的像素提供 min-height 和 max-height 吗?

html - css 更改 :visited 的背景位置

php - 菜单显示不正确

html - 将光标移到书签上时,如何防止书签改变样式?

html - 如何让背景图片覆盖整个页面

带有粘性标题的 JavaScript 库移动

javascript - 在函数中传递方法

html - 在 haskell 中生成 html 表的最简单方法是什么

jquery - 可见性 "animation"但 SCSS 中的反向效果有延迟

javascript - 在窗口中居中动态生成的表格单元格