Redirect to a specific part of the page with a link

混江龙づ霸主 提交于 2021-01-04 21:00:07

问题


This is my link to the specific page from another page.

<a href="http://test.com/#test"

and this is my part of page I want to display but it does not work...

<div id="test"><h4>Title of test</h4></div>

I am using WordPress, could it cause the problem?


回答1:


Change this:

<div id="test">
  <h4>
    Title of test
  </h4>
</div>

to this...

<a name="test">
  <h4> 
    Title of test
  </h4>
</a>

You should be able to link to it with this:

<a href="http://test.com/test-page#test">Test</a>



回答2:


In HTML, you can jump to a specific page section by using an anchor tag with a name or id attribute, like:

<a id="test"><h4>Title of test</h4></a> or <a name="test"><h4>Title of test</h4></a>

Actually, it looks like name was only for HTML4, ID is what should be used for HTML5 per here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-name



来源:https://stackoverflow.com/questions/28503383/redirect-to-a-specific-part-of-the-page-with-a-link

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!