我有一个网站:
http://cancersurvivorshipireland.com/cancersurvivorshipireland.com/wordpress/ (临时地址)
但我有所有的菜单标题标题相同的颜色,他们都是绿色的。我正试着把它们弄成不同的颜色。
例如:家=绿,新闻=红,博客=黄。但却完全不知道该怎么做?
发布于 2015-02-09 15:55:09
您可以使用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: orange;
}
#menu-default li:nth-child(5) a {
color: blue;
}发布于 2015-02-09 15:57:10
每个菜单项都有一个不同的id和一个匹配类,即li.menu-item-39也是li#menu-item-39。您可以使用CSS来针对这些ids或类,无论您更喜欢哪种类型。
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伪类来实现这一点,但这只能在支持CSS3的浏览器中工作。
发布于 2015-02-09 15:55:10
可以在list元素上使用*第九个孩子。将此添加到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; }https://stackoverflow.com/questions/28413666
复制相似问题