简体   繁体   English

如何创建内部链接(href =“#…” / PHP和Bootstrap

[英]How to create internal links (href=“#…” / PHP & Bootstrap

New to coding in general. 一般而言,是编码的新手。 Creating a simple small website as a class assignment. 创建一个简单的小型网站作为课程分配。 Using PHP with no frameworks and Bootstrap for the HTML-CSS. 使用没有框架的PHP和HTML-CSS的Bootstrap。 Cannot use JavaScript as per assignment requirements. 无法根据分配要求使用JavaScript。

I cannot find how to properly create internal links in a page. 我找不到如何在页面中正确创建内部链接的方法。

I use the URL to decide which page to show (all dealt from index.php). 我使用URL来决定显示哪个页面(全部由index.php处理)。 Links (via href) to diferent pages in the same website or external links work fine. 指向同一网站中不同页面的链接(通过href)或外部链接都可以正常工作。

But when I try to use what normally would be href="#idName" for a link pointing to the same page, it doesn't work. 但是,当我尝试使用通常将href =“#idName”指向指向同一页面的链接时,它将无法正常工作。

I assume it has something to do with how this information goes to the URL and is interpreted by the index.php. 我认为这与该信息如何到达URL以及由index.php解释有关。 But besides that, I'm lost. 但是除此之外,我迷路了。

Maybe because I don't have the right vocabulary to search for it, but so far, no luck when looking for the answer online. 也许是因为我没有合适的词汇来搜索它,但是到目前为止,在网上寻找答案时还没有运气。

Part of the index.php: index.php的一部分:

if (isset($_GET['action'])){
    if($_GET['action'] == 'profil-membre'){
        include('pages/header_menu.html'); 
        include('pages/profil-membre.php');
    }elseif ($_GET['action'] == 'page-activite'){
        include('pages/header_menu.html'); 
        include('pages/page-activite.php');
    }
}else{ 
    include('pages/header_menu.html'); 
    //and below the html for the main page.
?>

And part of the html in the pages where I would like an internal link: 我想要内部链接的页面中的html部分:

 <!--a menu as tabs (showing just the part with the problematic href-->
<li class="nav-item">
    <a class="nav-link" data-toggle="tab" href="#membre-exist">Membre Existant</a>
</li>

<!-- the href should point to the div with id "membre-exist" -->
<div class="tab-content card card-body mb-4">
    <div id="membre-exist" class="container tab-pane fade"><br>
        <form action=""> <!-- and the html code follows normally -->

Any ideas or links to where I could find the information to solve this would be appreciated!! 任何想法或链接,我可以在其中找到解决问题的信息!

If I understand the question correctly, you can use :target CSS pseudo element and use that to show the contents using display . 如果我对问题的理解正确,则可以使用:target CSS伪元素,并使用display元素显示内容。 I am doing something really simple for you. 我正在为您做一些非常简单的事情。

 * {margin: 0; padding: 0; line-height: 1; font-family: 'Segoe UI'; text-align: center; border-radius: 5px;} a {display: inline-block; padding: 5px; border: 1px solid #ccf; background-color: #eef; text-decoration: none;} a:active, a:focus {background: #f90; border-color: #f60;} section {margin: 10px; padding: 10px; border: 1px solid #ccf; background-color: #f5f5f5; display: none;} section:target {display: block;} 
 <a href="#one">one</a> <a href="#two">two</a> <a href="#three">three</a> <a href="#four">four</a> <section id="one"> This is section one. </section> <section id="two"> This is section two. </section> <section id="three"> This is section three. </section> <section id="four"> This is section four. </section> 

The above code acts like a tab view and it doesn't have any JavaScript or Server Side code. 上面的代码就像一个选项卡视图,并且没有任何JavaScript或服务器端代码。 It purely relies on the #hashvalue that's passed to the URL. 它纯粹依赖于传递给URL的#hashvalue The above code perfectly matches with your requirement: 上面的代码完全符合您的要求:

  • Doesn't use any server side language. 不使用任何服务器端语言。
  • Doesn't require JavaScript for this. 不需要JavaScript。

It's a pure CSS way of doing things. 这是一种纯CSS的处理方式。

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

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