【问题标题】:Link not Behaving as Expected When Linking to a Specific Part of a Web Page链接到网页的特定部分时,链接的行为不符合预期
【发布时间】:2020-01-31 04:52:32
【问题描述】:

我正在尝试链接到页面的特定部分。我已将href="#disclaimer" 属性添加到我希望访问的锚链接中,并且在要单击的实际链接上,我已将href 链接属性设置为href="./terms-conditions.php/#disclaimer"

该站点是当前托管在 localhost MAMP 服务器上的静态站点,但我不明白为什么链接不起作用。它确实进入了正确的页面,但没有直接进入该页面底部的#disclaimer href 链接,并且页面全部损坏,没有任何样式。当我通过主导航菜单正常访问该页面时,该页面一切正常。

我很困惑——任何帮助都会很棒。

艾米丽

<!-- Code with link to click -->

<p>Copyright © 2019 All rights reserved. <a title="disclaimer" href="./terms-conditions.php/#disclaimer">Disclaimer.</a> Authorised and regulated by the Solicitors Regulation Authority of England and Wales with registered number xxxxxx.</p>

<!-- Code code on the page you arrive at -->

<h3><a class="td" href="#disclaimer">Disclaimer</a></h3>
<p>The information you obtain at this site is not, nor is it intended to be, legal advice. You should consult a solicitor for advice regarding your individual situation. We invite you to contact us and welcome your calls, letters and electronic mail. Contacting us does not create a solicitor-client relationship. Please do not send any confidential information to us until such time as a solicitor-client relationship has been established.</p>

【问题讨论】:

  • 能否请您发布您的代码 - 特别是 href 部分和 #disclaimer 部分。但一切都会好起来的
  • 嗨@EGC 我已按要求添加了代码
  • 看我的回答:)

标签: html hyperlink anchor


【解决方案1】:

这就是你需要的!

(忽略巨大的div,它是表示它走到了正确的位置):)

  <p>Copyright © 2019 All rights reserved. <a title="disclaimer" 
  href="#disclaimer">Disclaimer.</a> Authorised and regulated by the 
  Solicitors Regulation Authority of England and Wales with registered 
  number 
  xxxxxx.</p>

    <!-- Spacer content -->
    <div style="height: 4000px">
    
    </div>

    <!-- Code code on the page you arrive at -->
    <h3><a class="td" id="disclaimer">Disclaimer</a></h3>
    <p>The information you obtain at this site is not, nor is it intended to be, legal advice. You should consult a solicitor for advice regarding your individual situation. We invite you to contact us and welcome your calls, letters and electronic mail. Contacting us does not create a solicitor-client relationship. Please do not send any confidential information to us until such time as a solicitor-client relationship has been established.</p>

那么,这行得通的原因是什么?

“#”标签作为page anchor 运行,它在其中查找关联的“id”标签并导航到它。结果,单击锚标记时,您“将跳转到同一页面的相应部分”(ref

要使这项工作专门针对您的网站,请使用以下代码:

<p>Copyright © 2019 All rights reserved. <a title="disclaimer" 
  href="./terms-conditions.php#disclaimer">Disclaimer.</a> Authorised and regulated by the 
  Solicitors Regulation Authority of England and Wales with registered 
  number 
  xxxxxx.</p>

    <!-- Spacer content -->
    <div style="height: 4000px">
    
    </div>

    <!-- Code code on the page you arrive at -->
    <h3><a class="td" id="disclaimer">Disclaimer</a></h3>
    <p>The information you obtain at this site is not, nor is it intended to be, legal advice. You should consult a solicitor for advice regarding your individual situation. We invite you to contact us and welcome your calls, letters and electronic mail. Contacting us does not create a solicitor-client relationship. Please do not send any confidential information to us until such time as a solicitor-client relationship has been established.</p>

【讨论】:

  • 这不起作用。它在我所做的网站上的“免责声明”元素位于不同的页面上。仅当它在同一页面上时才有效。
  • 这一行 href="./terms-conditions.php#disclaimer" 按照最终代码 sn-p 将允许它重定向到页面 terms-conditions.php 虽然
猜你喜欢
  • 2013-03-07
  • 2013-01-03
  • 2021-11-19
  • 2012-01-15
  • 2018-06-13
  • 1970-01-01
  • 2012-11-05
  • 2015-02-16
相关资源
最近更新 更多