Need to change the Colour of each menu heading. -

2019-09-20 02:58发布

I have a website:

http://cancersurvivorshipireland.com/cancersurvivorshipireland.com/wordpress/ (temp address)

but I have all the menu topics in the header the same colour, they are all green. I am trying to get them all different colours.

eg. Home = green, News = red, Blog = yellow. but have absolutely no idea how to do it?

4条回答
萌系小妹纸
2楼-- · 2019-09-20 03:34

You can do this with CSS nth child selector as follows:

#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;
}
查看更多
爷、活的狠高调
3楼-- · 2019-09-20 03:44

Each of those menu items have a distinct id and a matching class, i.e., li.menu-item-39 is also li#menu-item-39. You can use CSS to target these ids or classes, whichever you are more comfortable with.

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

Edited to address other answers: You can use the :nth-child pseudo-class to do this, but that will only work in browsers that support CSS3.

查看更多
萌系小妹纸
4楼-- · 2019-09-20 03:51

You would need to get into the navigation.php file I'm presuming and add css id parameters to each and then give them any entry in styles.css to assign the color.

If you're not familiar with editing the files or changing code it's not an easy fix.

Here's some css code:

#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; }
查看更多
闹够了就滚
5楼-- · 2019-09-20 03:56

You can use :nth-child on the list element. Add this to your css file

#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; }
查看更多
登录 后发表回答