需要更改每个菜单标题的颜色。 - WordPress的

Need to change the Colour of each menu heading. - Wordpress

我有一个网站:

http://cancersurvivorshipireland.com/cancersurvivorshipireland.com/wordpress/ (临时地址)

但是我在 header 中的所有菜单主题都是相同的颜色,它们都是绿色的。我正在尝试让它们具有不同的颜色。

例如。主页 = 绿色,新闻 = 红色,博客 = 黄色。但完全不知道该怎么做?

您可以使用 CSS nth child selector 执行此操作,如下所示:

#menu-default li:nth-child(1) a { 
    color: green;
}
#menu-default li:nth-child(2) a { 
    color: red;
}
#menu-default li:nth-child(3) a { 
    color: yellow;
}
#menu-default li:nth-child(4) a { 
    color: orange;
}
#menu-default li:nth-child(5) a { 
    color: blue;
}

您可以在列表元素上使用 :nth-child。将此添加到您的 css 文件

#menu-default > li:nth-child(1) > a { color: green; }
#menu-default > li:nth-child(2) > a { color: red; }
#menu-default > li:nth-child(3) > a { color: yellow; }
#menu-default > li:nth-child(4) > a { color: white; }
#menu-default > li:nth-child(5) > a { color: orange; }

每个菜单项都有一个不同的 ID 和一个匹配的 class,li.menu-item-39 也是 li#menu-item-39。您可以使用 CSS 来定位这些 ID 或 classes,以您更喜欢的方式为准。

li.menu-item-39 > a { /* Home */
  color: green;
}
li.menu-item-43 > a { /* News */
  color: red;
}
li.menu-item-47 > a { /* Blog */
  color: yellow;
}

编辑以解决其他答案:您可以使用 :nth-child 伪 class 来执行此操作,但这仅适用于支持的浏览器CSS3.

您需要进入我假设的 navigation.php 文件并为每个文件添加 css id 参数,然后在 styles.css 中给它们任何条目以分配颜色。

如果您不熟悉编辑文件或更改代码,这不是一件容易的事。

这是一些 css 代码:

#menu-default > li:nth-child(1) > a { color: green; }
#menu-default > li:nth-child(2) > a { color: red; }
#menu-default > li:nth-child(3) > a { color: yellow; }
#menu-default > li:nth-child(4) > a { color: white; }
#menu-default > li:nth-child(5) > a { color: orange; }