好了,这是我的两难选择。我有一个包含标题信息(导航和徽标)的header.php文件,这样我就可以在每个my pages中需要它的地方包含该文件,并使其更易于编辑。我的问题是,我显然不能使用:active来着色或更改链接文本,以便用户知道他们在哪个页面上。
我如何才能用我正在做的方式实现我想要的东西,或者我被困在了很长的一段路上。有没有javascript可以做到这一点。
了解我是新的HTML和CSS,并正在寻找简单的方法来改变页眉和页脚,而不必单独编辑每个页面。
马科斯
发布于 2014-03-23 06:52:13
我不知道你的html是什么样子的,但是例如,如果你包含了jQuery,并且你在链接中使用了绝对补丁,你可以使用这样的东西:
$('a[href="'+document.location.origin+document.location.pathname+'"]').css('color', '#f00');或者,如果你没有jQuery,但有绝对链接,你可以使用这样的东西:
var a = document.getElementsByTagName('a');
for (i in a) {
if (a[i].href == document.location.origin+document.location.pathname){
// red color
a[i].style.color = '#900'
}
}发布于 2014-03-23 06:35:27
将以下CSS添加到您的代码中。然后将类应用于您的<a>标记。
1.
/*choose current(active) a tag which has class named niceClass*/
.niceClass a.current {color:red;}2.
<a href="http://www.example.com" class="niceClass"> Link Title </a>
<a href="http://www.example.com2" class="niceClass"> Link Title2 </a>
...https://stackoverflow.com/questions/22584311
复制相似问题