如果一个 div 是 display:none,是否允许在 div 元素中使用连续的同名锚点?
Are consecutive anchors with the same name allowed in div elements if one div is display:none?
我正在创建一个页面,该页面有两个 div 元素,正上方是我要为其创建锚点的文本。 div 元素之一在特定屏幕尺寸以上 display:none,而另一个 div 元素是 display:block,如下所示:
<div class="hidden"><!-- This div class is set to display:none; in CSS -->
<!-- Div content -->
</div>
<div class="show"><!-- This div class is set to display:none; in CSS -->
<!-- Div content -->
</div>
<a name="anchor"></a>
<h2>Paragraph heading</h2>
<p>Paragraph that I want to anchor to</p>
当我如上例所示放置锚点时,它实际上出现在段落标题下方。是否允许放两个同名的anchor,如果div其中一个是display:none,像这样:
<div class="hidden">
<!-- Div content -->
<a name="anchor"></a>
</div>
<div class="show">
<!-- Div content -->
<a name="anchor"></a>
</div>
<h2>Paragraph heading</h2>
<p>Paragraph that I want to anchor to</p>
有没有办法允许这样的事情?我已经对此进行了测试,锚点的 link 似乎不起作用 - display:none div 中的 HTML 标记是否与 [=25] 中的标记冲突=] div,即使浏览器不显示一个div元素?
我能在 Stack Overflow 上找到的唯一示例是:,它似乎与 javascript 切换有关,而不是我的问题。如果其他地方有答案,请告诉我。
没有。参见 the specification
If the attribute is present, its value must not be the empty string and must neither be equal to the value of any of the IDs in the element's home subtree other than the element's own ID, if any, nor be equal to the value of any of the other name attributes on a elements in the element's home subtree.
在文档中必须是唯一的。你如何为它周围的元素设置样式与该规则无关。
规范还说:
Authors should not specify the name attribute on a elements.
a
元素上的 name
属性在 1996 年发布 HTML 4 时被取代并引入了 id
属性(在任何元素上,而不仅仅是在锚上).
id
在文档中也必须是唯一的。
我正在创建一个页面,该页面有两个 div 元素,正上方是我要为其创建锚点的文本。 div 元素之一在特定屏幕尺寸以上 display:none,而另一个 div 元素是 display:block,如下所示:
<div class="hidden"><!-- This div class is set to display:none; in CSS -->
<!-- Div content -->
</div>
<div class="show"><!-- This div class is set to display:none; in CSS -->
<!-- Div content -->
</div>
<a name="anchor"></a>
<h2>Paragraph heading</h2>
<p>Paragraph that I want to anchor to</p>
当我如上例所示放置锚点时,它实际上出现在段落标题下方。是否允许放两个同名的anchor,如果div其中一个是display:none,像这样:
<div class="hidden">
<!-- Div content -->
<a name="anchor"></a>
</div>
<div class="show">
<!-- Div content -->
<a name="anchor"></a>
</div>
<h2>Paragraph heading</h2>
<p>Paragraph that I want to anchor to</p>
有没有办法允许这样的事情?我已经对此进行了测试,锚点的 link 似乎不起作用 - display:none div 中的 HTML 标记是否与 [=25] 中的标记冲突=] div,即使浏览器不显示一个div元素?
我能在 Stack Overflow 上找到的唯一示例是:
没有。参见 the specification
If the attribute is present, its value must not be the empty string and must neither be equal to the value of any of the IDs in the element's home subtree other than the element's own ID, if any, nor be equal to the value of any of the other name attributes on a elements in the element's home subtree.
在文档中必须是唯一的。你如何为它周围的元素设置样式与该规则无关。
规范还说:
Authors should not specify the name attribute on a elements.
a
元素上的 name
属性在 1996 年发布 HTML 4 时被取代并引入了 id
属性(在任何元素上,而不仅仅是在锚上).
id
在文档中也必须是唯一的。