根据页面更改导航项颜色

时间:2014-05-27 11:23:49

标签: css wordpress

我正在尝试根据您所在的页面更改导航链接的颜色。这是一个固定的标题。 (Here是我网站的链接)。

例如,在首页上它是黑色的,易于阅读 -

enter image description here

但是当你去网站的帖子时,背景是黑色的,导致无法读取导航链接 -

enter image description here

是否可以根据帖子的ID更改导航链接?

3 个答案:

答案 0 :(得分:1)

您可以通过post unique slug给出body标签类。

<body class="<?php print $post->post_name; ?>">

就像here一样:

<body class="blackfoot-phoenix">

然后在css中:

.blackfoot-phoenix #cats li a {
    color: white;
}

你也可以使用在body类中的post id:postid-193。

.postid-193 #cats li a {
        color: white;
}

如果您右键单击并执行&#34;查看页面来源&#34;您可以看到postid。

答案 1 :(得分:0)

<style type='text/css'> 
  #black a { color:black }
  #white a { color:white }
</style>

...

<a id="<?php echo$color;?>" href="" ></a>

答案 2 :(得分:0)

根据您希望得到的结果,您可以使用css在标题链接上给它一个白色背景:

#cats li a {
  text-decoration: none !important;
  background-color: #fff;
}

这样做会显得正常,但在黑暗的背景下,文字背后会显示白色。或者,您可以为其分配一个类,并使用类在每页上进行设置。 Wordpress每页设置不是很友好,但可能有一些插件可用。尝试这样的事情:https://wordpress.org/plugins/stylesheet-per-page/installation/

相关问题