Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 第一个子项选择不起作用_Html_Css - Fatal编程技术网

Html 第一个子项选择不起作用

Html 第一个子项选择不起作用,html,css,Html,Css,当我试图通过调用css:first-child属性来选择第一篇文章的img时,它并没有选择。我使用了.widget\u ci-latest-posts文章:first child,但它没有选择 <aside class="widget_ci_latest-posts"> <h2>test</h2> <article class="item"> <figure class="item-thumb"> <a>

当我试图通过调用css:first-child属性来选择第一篇文章的img时,它并没有选择。我使用了.widget\u ci-latest-posts文章:first child,但它没有选择

<aside class="widget_ci_latest-posts">
<h2>test</h2>
<article class="item">
   <figure class="item-thumb">
       <a><img class="x" src="" /></a>
   </figure>
</article>

<article class="item">
   <figure class="item-thumb">
       <a><img class="x" src="" /></a>
   </figure>
</article>

<article class="item">
   <figure class="item-thumb">
       <a><img class="x" src="" /></a>
   </figure>
</article>
</aside>

测试

widget\u ci\u latest-posts
在CSS上它的非
-
应该是
ci
之后
widget\u ci\u latest-posts
在CSS上它的非
-
应该是
ci
之后
选择第一篇
文章
而不是
第一个孩子
,因为第一个孩子是
h2
元素而不是
文章

.widget\u ci\u最新文章:img类型的第一篇{
边框:5px纯黑;
}

测试

要选择first
article
您应该使用
first-of-type()
而不是
first-child
,因为第一个子元素是
h2
元素而不是
article

.widget\u ci\u最新文章:img类型的第一篇{
边框:5px纯黑;
}

测试

您使用了错误的类名。您的类称为widget_ci_latest-posts,您使用.widget_ci-latest-posts作为选择器。检查下划线。

您使用了错误的类名。您的类称为widget_ci_latest-posts,您使用.widget_ci-latest-posts作为选择器。检查下划线。

因为类widget\u ci\u latest-posts也有一个标记
h2
您是否尝试过
.widget\u ci-latest-posts.item:first child
?@tR4xX是我尝试过,但是不起作用。检查Nelson的答案有一个输入错误。因为类widget\u ci\u latest-posts也有一个标签
h2
。widget\u ci-latest-posts.item:first child
?@tR4xX我试过了,但没有起作用。检查Nelson的答案有一个输入错误。。