Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
Css 最后一个孩子不上课。最后一种类型也不工作_Css_Wordpress_Css Selectors - Fatal编程技术网

Css 最后一个孩子不上课。最后一种类型也不工作

Css 最后一个孩子不上课。最后一种类型也不工作,css,wordpress,css-selectors,Css,Wordpress,Css Selectors,我试图在我的style.css文件中选择一系列wordpress文章(具有相同的类)的最后一个子项。 以下是我的文档结构的简化版本: <div id="container"> <div id="content"> <!--start .post--> <div id="post-33" class="hentry p1 post"> <h2 class="entry-title"><a hr

我试图在我的style.css文件中选择一系列wordpress文章(具有相同的类)的最后一个子项。 以下是我的文档结构的简化版本:

<div id="container">
    <div id="content">
  <!--start .post-->
  <div id="post-33" class="hentry p1 post">
            <h2 class="entry-title"><a href="url">Post 1</a></h2>
            <div class="entry-content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
        </div>
  <!--end  .post -->
  <!--start .post-->
  <div id="post-24" class="hentry p1 post">
    <h2 class="entry-title"><a href="url">Post 2</a></h2>
    <div class="entry-content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
  </div>
  <!--end  .post -->
  <!--start .post-->
  <div id="post-24" class="hentry p1 post">
    <h2 class="entry-title"><a href="url">Post 3</a></h2>
    <div class="entry-content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
  </div>
  <!--end  .post -->

        <div id="nav-below" class="navigation">
            <div class="nav-previous"></div>
            <div class="nav-next"></div>
        </div>
    </div><!-- #content -->
</div><!-- #container -->
有什么想法吗?
这是我的站点的实时版本:

使用
n个类型的
n个最后一个类型的

.post:nth-of-type(1) .entry-content { 
    background-color: red; 
    border-bottom: 0px solid;
}

.post:nth-last-of-type(2) .entry-content { 
    background-color: yellow; 
    border-bottom: 0px solid;
}
first child
last child
,顾名思义,都是用于对子元素进行操作的,因此您需要使用
#content:last child
查找最后一个元素(不一定是
.post


post
的最后一个元素不是其父元素的最后一个子元素;并且没有类的最后一个伪类选择器。这不起作用,
:类型的最后一个
不查看元素的类名,只查看其“标记名”。谢谢Tomek。谢谢,但没用。。。相同的结果:第一个类型有效,但最后一个类型无效。你是对的,对不起。我更正了我的答案。谢谢托梅克。第n种类型和第n种类型完成了任务。非常感谢。很高兴我帮了忙;-)
.post:nth-of-type(1) .entry-content { 
    background-color: red; 
    border-bottom: 0px solid;
}

.post:nth-last-of-type(2) .entry-content { 
    background-color: yellow; 
    border-bottom: 0px solid;
}