简体   繁体   English

锚标记div名称

[英]anchor tag div name

I'm running into some trouble here, all help appreciated. 我在这里遇到了一些麻烦,感谢所有帮助。 I'm trying to link to a certain section on my page. 我正在尝试链接到页面上的特定部分。 But I'm having trouble. 但是我有麻烦了。 check my code: 检查我的代码:

<a href="#h2">Consulting</a>

That's the link, here's the block I'm wanting to link to: 那是链接,这是我要链接的块:

<div class="space" name="h2">
  <h1 class="h2">Consulting</h1>    
  <p class="paragraph">BLAH</p> 
</div>

Now I think I have it wrong, but I'm trying not to keep it messy. 现在,我认为我做错了,但我尝试不让它保持混乱。 But would I have to do 但是我必须做

<a name="h2">BLAH</a>

to make it work, or can I do what I was doing, and am I missing something? 使它起作用,还是我可以做我正在做的事情,而我是否缺少某些东西?

With URL fragments you want to target the ID, not the class. 对于URL片段,您要定位ID,而不是类。 Change it to: 更改为:

<div class="space" name="h2">
  <h1 id="h2" class="h2">Consulting</h1>    
  <p class="paragraph">BLAH</p> 
</div>

Per MDN: 每个MDN:

A URL fragment is a name preceded by a hash mark (#), which specifies an internal target location ( an ID ) within the current document. URL片段是一个名称,其前面带有井号(#),该井号指定了当前文档中的内部目标位置( ID )。

See also: http://www.w3.org/TR/html401/struct/links.html#h-12.2.3 另请参阅: http : //www.w3.org/TR/html401/struct/links.html#h-12.2.3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM