How do I link to part of a page? (hash?)

后端 未结 7 1317
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 07:14
相关标签:
7条回答
  • 2020-11-22 07:39

    If there is any tag with an id (e.g., <div id="foo">), then you can simply append #foo to the URL. Otherwise, you can't arbitrarily link to portions of a page.

    Here's a complete example: <a href="http://example.com/page.html#foo">Jump to #foo on page.html</a>

    Linking content on the same page example: <a href="#foo">Jump to #foo on same page</a>

    It is called URL fragment.

    0 讨论(0)
  • 2020-11-22 07:39

    Provided that any element has the id attribute on a webpage. One could simply link/jump to the element that is referenced by the tag.

    Within the same page:

    <div id="markOne"> ..... </div> 
       ......
    <a href="#markOne">Jump to markOne</a> 
    

    Other page:

    <div id="http://randomwebsite.com/mypage.html#markOne"> 
      Jumps to the markOne element in the mypage of the linked website
    </div>
    

    The targets don't necessarily have an anchor element.

    You can go check this fiddle out.

    0 讨论(0)
  • 2020-11-22 07:41

    You have two options:

    You can either put an anchor in your document as follows:

    <a name="ref"></a>
    

    Or else you give an id to a any HTML element:

    <h1 id="ref">Heading</h1>
    

    Then simply append the hash #ref to the URL of your link to jump to the desired reference. Example:

    <a href="document.html#ref">Jump to ref in document.html</a>
    
    0 讨论(0)
  • 2020-11-22 07:42

    You use an anchor and a hash. For example:

    Target of the Link:

     <a name="name_of_target">Content</a>
    

    Link to the Target:

     <a href="#name_of_target">Link Text</a>
    

    Or, if linking from a different page:

     <a href="http://path/to/page/#name_of_target">Link Text</a>
    
    0 讨论(0)
  • 2020-11-22 07:42

    Just append a hash with an ID of an element to the URL. E.g.

    <div id="about"></div>
    

    and

    http://mysite.com/#about
    

    So the link would look like:

    <a href="http://mysite.com/#about">About</a>
    

    or just

    <a href="#about">About</a>
    
    0 讨论(0)
  • 2020-11-22 07:49

    Here is how:

    <a href="#go_middle">Go Middle</a>
    
    <div id="go_middle">Hello There</div>
    
    0 讨论(0)
提交回复
热议问题