问题描述
所以,我运行我的教会的网站,我尽量保持编码的基础,但我们有季节性页面,我们随时都会从网站上添加和删除,所以我厌倦了更改简单HTML代码导航栏的每个页面。我已经找到了可以使用PHP的地方,并且有一个代码,但是可以突出显示当前页面,即在我们的网站上,当前页面名称是粗体和不同的颜色。我也看到JS这样做(突出显示当前页面但我并不真正理解如何实现这一点,所以如果你认为这对我来说可能是更好的途径,并且可以帮助解释如何去做,那很酷。
b$ b
任何帮助都会很棒!
添加 id
属性添加到每个页面的 body
标记中,如下所示:
< body id =home> <! - 这将以您的主页为例 - >
...
< body id =about> <! - 这将用于您的关于网页... - >
将相同的内容添加到 li
标记中您的导航,如下所示:
< li id =home>主页< / li>
< li id =about>关于< / li>
然后在CSS文件中做到这一点:
body#home li#home,body#about li#about {//活动菜单项的样式}
So, I run my church's website and I try to stay pretty basic in the coding, but we have seasonal pages that we add and remove from the website all the time so I get tired of changing the "simple" HTML code on every page for the nav bar. I have found where I can use PHP and have one code, like but is it possible to have the current page highlighted, i.e. on our website now, the current page name is bold and a different color.
I have also seen JS do this (Highlighting current page in the nav) but I don't really understand how to implement this, so if you think this could be the better route for me, and can help explain how to do it, that would be cool.
Any help would be great!
add an id
attribute to the body
tag of each of your pages, like this:
<body id="home"> <!-- this would be for your home page for example -->
...
<body id="about"> <!-- this would be for your about page... -->
add the same to the li
tags of your nav, like this:
<li id="home">Home</li>
<li id="about">About</li>
then in the CSS file just do this:
body#home li#home, body#about li#about { // style of the active menu item }
这篇关于如何在多个页面上使用一个Nav Bar代码,但是当前页面是否突出显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!