hr 元素不能用作锚点有什么原因吗?
Is there a reason why hr elements cannot be used as anchors?
我有一个标准常见问题解答格式的网页,每个问题都列为 link 答案。
我们有几个 hr
元素用作锚点 - 每个元素都分配了唯一的 id
属性 - 但 links 似乎没有正常工作。
锚点 links 似乎可以与其他元素一起使用,但 hr
不行 - 我在网上找不到任何暗示 hr
元素不能作为锚点的内容。
出于某种原因,我可以不使用 hr
元素作为锚点 link 目的地吗?
示例,使用编辑后的内容:
<ul>
<li><a href="#requirements">What are the technical requirements for using the online application system?</a></li>
<li><a href="#jobboard">Which job board should I use to apply for a position?</a></li>
</ul>
<hr id="requirements" />
<h3>What are the technical requirements for using the online application system?</h3>
<hr />
<p>The COMPANY uses an online application system for most of our job postings. This system lets you create a profile to keep track of the positions you’ve applied for, provides confirmation that your application has been accepted, allows you to edit submitted applications up until the posting closing date, and notifies you via email of jobs that match your skills and interests.</p>
<hr id="jobboard" />
<h3>Which job board should I use to apply for a position?</h3>
<hr />
<p>COMPANY has a variety of employee groups, and certain groups may apply for positions on specific job boards. Here is a summary of what job board you should be checking:</p>
I can't find anything online suggesting that hr
elements cannot be targeted as anchor points.
规范要求 any element with an ID may be designated as the target of a URL fragment。未说明任何例外情况,这意味着该规则适用于 hr
.
链接到 hr
元素无效似乎是 Google Chrome 的问题。它在所有其他浏览器上工作得很好。我认为这是一个 Chrome 错误。
作为解决方法,删除 hr
元素(全部)并将 ID 重新分配给 h3
元素。这就是 ID 的用途。 hr
元素仅在将单个部分划分为子标题不必要或不合适的离散小节时才需要。由于 FAQ 中的每个条目都是一个独立的部分,有自己的标题,所以那些 hr
最多是多余的,最坏的情况下是不合适的。如果您希望在部分之间出现水平线,请使用 CSS 添加边框,而不是使用 hr
元素。
<ul>
<li><a href="#requirements">What are the technical requirements for using the online application system?</a></li>
<li><a href="#jobboard">Which job board should I use to apply for a position?</a></li>
</ul>
<h3 id="requirements">What are the technical requirements for using the online application system?</h3>
<p>The COMPANY uses an online application system for most of our job postings. This system lets you create a profile to keep track of the positions you’ve applied for, provides confirmation that your application has been accepted, allows you to edit submitted applications up until the posting closing date, and notifies you via email of jobs that match your skills and interests.</p>
<h3 id="jobboard">Which job board should I use to apply for a position?</h3>
<p>COMPANY has a variety of employee groups, and certain groups may apply for positions on specific job boards. Here is a summary of what job board you should be checking:</p>
理论上是 HTML 5 Specification does support the use of an ID
attribute on an <hr>
element (via support for Global Attributes) ,但实际上,这将归结为哪些浏览器支持这种做法的问题。
如果您发现某些浏览器无法正常工作,我强烈建议您使用更常见的编码技术重新编写 HTML 代码,例如使用 <div>
或 <a>
元素代替。
我有一个标准常见问题解答格式的网页,每个问题都列为 link 答案。
我们有几个 hr
元素用作锚点 - 每个元素都分配了唯一的 id
属性 - 但 links 似乎没有正常工作。
锚点 links 似乎可以与其他元素一起使用,但 hr
不行 - 我在网上找不到任何暗示 hr
元素不能作为锚点的内容。
出于某种原因,我可以不使用 hr
元素作为锚点 link 目的地吗?
示例,使用编辑后的内容:
<ul>
<li><a href="#requirements">What are the technical requirements for using the online application system?</a></li>
<li><a href="#jobboard">Which job board should I use to apply for a position?</a></li>
</ul>
<hr id="requirements" />
<h3>What are the technical requirements for using the online application system?</h3>
<hr />
<p>The COMPANY uses an online application system for most of our job postings. This system lets you create a profile to keep track of the positions you’ve applied for, provides confirmation that your application has been accepted, allows you to edit submitted applications up until the posting closing date, and notifies you via email of jobs that match your skills and interests.</p>
<hr id="jobboard" />
<h3>Which job board should I use to apply for a position?</h3>
<hr />
<p>COMPANY has a variety of employee groups, and certain groups may apply for positions on specific job boards. Here is a summary of what job board you should be checking:</p>
I can't find anything online suggesting that
hr
elements cannot be targeted as anchor points.
规范要求 any element with an ID may be designated as the target of a URL fragment。未说明任何例外情况,这意味着该规则适用于 hr
.
链接到 hr
元素无效似乎是 Google Chrome 的问题。它在所有其他浏览器上工作得很好。我认为这是一个 Chrome 错误。
作为解决方法,删除 hr
元素(全部)并将 ID 重新分配给 h3
元素。这就是 ID 的用途。 hr
元素仅在将单个部分划分为子标题不必要或不合适的离散小节时才需要。由于 FAQ 中的每个条目都是一个独立的部分,有自己的标题,所以那些 hr
最多是多余的,最坏的情况下是不合适的。如果您希望在部分之间出现水平线,请使用 CSS 添加边框,而不是使用 hr
元素。
<ul>
<li><a href="#requirements">What are the technical requirements for using the online application system?</a></li>
<li><a href="#jobboard">Which job board should I use to apply for a position?</a></li>
</ul>
<h3 id="requirements">What are the technical requirements for using the online application system?</h3>
<p>The COMPANY uses an online application system for most of our job postings. This system lets you create a profile to keep track of the positions you’ve applied for, provides confirmation that your application has been accepted, allows you to edit submitted applications up until the posting closing date, and notifies you via email of jobs that match your skills and interests.</p>
<h3 id="jobboard">Which job board should I use to apply for a position?</h3>
<p>COMPANY has a variety of employee groups, and certain groups may apply for positions on specific job boards. Here is a summary of what job board you should be checking:</p>
理论上是 HTML 5 Specification does support the use of an ID
attribute on an <hr>
element (via support for Global Attributes) ,但实际上,这将归结为哪些浏览器支持这种做法的问题。
如果您发现某些浏览器无法正常工作,我强烈建议您使用更常见的编码技术重新编写 HTML 代码,例如使用 <div>
或 <a>
元素代替。