doudun2565 2018-04-01 10:34
浏览 27

使特定网页的导航链接最新

I want to create current state for my nav links in my website. For example when I click "Contacts" the link refers me to contacts page and I want the link "contacts" in nav to change his color.

The problem is that I'm including the header from external html file in all my webpages with php. So if I edit this external header file the changes will affect all other pages not only the contacts page.

  • 写回答

1条回答 默认 最新

  • duan5362 2018-04-01 10:53
    关注

    You can set the id of the body of the page to some value that represents the current page. Then for each element in the menu you set a class specific to that menu item. And within your CSS you can set up a rule that will highlight the menu item specifically.

    That probably didn't make much sense, so here's an example:

    <body id="index">
    <div id="menu">
     <ul>
      <li class="index"     ><a href="index.html">Index page</a></li>
      <li class="contact"     ><a href="contact.html">Page 1</a></li>
     </ul>
    </div> <!-- menu -->
    </body>
    

    In your contact.html, you would set the id of the body to: id="contact".

    Finally in your CSS you have something like the following:

    #index #menu .index, #contact #menu .contact{
      font-weight: bold;
    }
    

    You would need to alter the ID for each page, but the CSS remains the same, which is important as the CSS is often cached and can require a forced refresh to update.

    It's not dynamic, but it's one method that's simple to do, and you can just include the menu html from a template file using PHP or similar.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用