Ссылка не ведет себя так, как ожидалось при ссылке на определенную часть веб-страницы - PullRequest
1 голос
/ 02 октября 2019

Я пытаюсь дать ссылку на определенную часть страницы. Я добавил атрибут href="#disclaimer" к ссылке привязки, по которой я хочу перейти, и по фактической ссылке, по которой нужно щелкнуть, я сделал атрибут ссылки href как href="./terms-conditions.php/#disclaimer"

Сайт является статическимсайт в настоящее время размещается на локальном сервере 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>

1 Ответ

0 голосов
/ 02 октября 2019

Это то, что вам нужно!

(Игнорировать гигантский 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>

Итак, почему это работает?

Тег '#' работает как якорь страницы , где он ищетсвязанный тег '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>
...