我试图使用:nth-child伪类为标题文本旁边的每个侧栏小部件标题提供独特的背景颜色和图标。:nnth-child不能用于Wordpress小部件标题
此刻,它显示所有3个侧边栏小部件标题的第n个子项(1)的背景颜色和背景图像,而不是:第n个子项(1)代表Twitter,第n个子项(2)投票和:第n孩子(3)的Instagram。
.main .sidebar .widgettitle:nth-child(1) {
background-color: #25abdc !important;
color: #ffffff;
background-image: url('/wp-content/uploads/2014/08/twitter-icon.png');
background-repeat: no-repeat !important;
background-position: 15% !important;
}
.main .sidebar .widgettitle:nth-child(2) {
background-color: #f18484 !important;
color: #FFFFFF;
background-image: url('/wp-content/uploads/2014/08/poll-icon.png');
background-repeat: no-repeat !important;
background-position: 15% !important;
}
.main .sidebar .widgettitle:nth-child(3) {
background-color: #25abdc !important;
color: #ffffff !important;
background-image: url('/wp-content/uploads/2014/08/instagram-icon.png') ;
background-repeat: no-repeat !important;
background-position: 15% !important;
}
该URL是http://1musicnetworks.kingly.co.za/。
因为它是'nth-child'而不是'nth-class'。 CSS伪类,如':nth-child',':nth-of-type',...匹配父级的子树中的元素的第n个子元素*或*类型。他们不查看类的列表。 – 2014-08-28 20:10:28
[CSS选择器的第一个元素与类](http://stackoverflow.com/questions/2717480/css-selector-for-first-element-with-class) – 2014-08-28 20:12:18
请阅读[如何创建一个最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。在这种情况下,除了发布所有相关的代码之外,还可以添加一个演示问题的小提琴。 。 。 。哦,是的,在问之前研究这个网站是必不可少的。祝你好运! – brasofilo 2014-08-28 20:13:09