cssnth子选择器-样式

cssnth子选择器-样式,css,css-selectors,Css,Css Selectors,您对css规则有问题。写成 abc a:nth-child(2) { text-weight:bold !important; } 为了达到你想要的效果,改变你的css为 .abc a:nth-child(2) { font-weight:bold !important; } 现在试试这个 a.abc { font-weight:bold!important; } .def{ font-weight:normal!important;

您对css规则有问题。写成

abc a:nth-child(2) {
text-weight:bold !important;
}
为了达到你想要的效果,改变你的css为

   .abc a:nth-child(2) {
    font-weight:bold !important;
    }

现在试试这个

    a.abc {
    font-weight:bold!important;
    }
.def{
    font-weight:normal!important;
    }


​

你可以做一个技巧来做到这一点

.abc:nth-child(2) {
font-weight:bold !important;
}
HTML

.abc
{
  font-weight:bold;
}
.def{

font-weight:normal;
}

当您通过第n个子css进行定位时,您必须将条形文本放在span coz中,您必须显示相同的标记我创建了两个示例检查此小提琴

并使用下面的代码

<a class="abc">
     <span class="def">foo</span>
     bar
</a>
.abc:n第n个子项(2){
字体大小:粗体;
}
福
酒吧
​

你不能给出。abc粗体和def正常吗?它是
。abc
不是
abc
并且它是
字体重量
不是
文本重量
。这不是一个好方法,你可以在我的示例中看到下面的子css。你试过了吗?它在这里不起作用,你的代码只对
span
文本(即foo)工作得很好,但在问题中,他试图用粗体显示文本
bar
,而您的代码不适用于文本
bar
,我在这里更新了您的小提琴
<a class="abc">
     <span class="def">foo</span>
     bar
</a>
.abc :nth-child(2) {
    font-weight:bold;
}

<a class="abc">
     <span class="def">foo</span>
     <span>bar</span>
   </a>​