css3 last-child没有按预期工作

azz*_*z0r 3 css css-selectors css3

我有动态生成的匹配列表.在每个成员之后,我显示一个在其中显示VS的li.然而,div匹配中的最后一个ul li应该是不可见的.我有什么想法可以做到这一点?HTML

<style>
    .match {
    }
    .match ul {
    }
    .match ul li {
        float: left;
        margin-right: 50px;
    } 
    .match ul li:last-child {
        display: none;
    }
</style>

  <div class="content">
    <div class="match">
      <ul>
        <li><a href="/wade-barrett/member">Wade Barrett</a></li>
        <li style="">VS</li>
      </ul>

      <ul>
        <li><a href="/shaemus/member">Shaemus</a></li>
        <li style="">VS</li>
      </ul>

      <ul>
        <li><a href="/randy-orton/member">Randy Orton</a></li>
        <li style="">VS</li>
      </ul>

      <ul>
        <li><a href="/john-cena/member">John Cena</a></li>
        <li style="">VS</li>
      </ul>

      <ul>
        <li><a href="/edge/member">Edge</a></li>
        <li style="">VS</li>
      </ul>

      <ul>
        <li><a href="/chris-jericho/member">Chris Jericho</a></li>
        <li style="">VS</li>
      </ul>

      <p class="clear"></p>
    </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

Bol*_*ock 10

:last-child伪类应适用于ul,不li,因为你想要的最后文本VS ul列表被隐藏.通过应用伪类li,你申请样式最后li每一个 ul,这是不正确.

您还应该使用VS文本将class属性应用于li元素,以便与类选择器匹配更方便.

更改

<li style="">VS</li>
Run Code Online (Sandbox Code Playgroud)

<li class="vs">VS</li>
Run Code Online (Sandbox Code Playgroud)

并使用它代替当前的:last-child选择器:

.match ul:last-child li.vs {
    display: none;
}
Run Code Online (Sandbox Code Playgroud)