You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

不使用:nth伪类等受限选择器,如何选中指定marble类div?

竞赛备赛问题:选中指定.marble元素

我正在为高中生区域Web开发竞赛做准备,需要完成竞赛网站上的备赛任务,现有如下HTML代码:

<h2>Task 6</h2>
  <article id="task-6">
    <div class="marble" data-target></div>
    <section class="first">
      <div class="marble" data-target></div>
      <div class="marble"></div>
      <div class="marble" data-target></div>
    </section>
    <div class="marble"></div>
    <section class="last">
      <div class="marble" data-target></div>
      <div class="marble"></div>
      <div class="marble" data-target></div>
    </section>
    <div class="marble" data-target></div>
  </article>

我的目标是选中带有data-target属性的.marble类div,但必须遵守以下要求:

  • 禁止使用以下CSS伪类或选择器:
    • :nth-child
    • :nth-last-child
    • :nth-of-type
    • :nth-last-of-type
    • [data-target]
    • 同时禁止使用+或~
  • 仅允许使用一个选择器。

我尝试了如下选择器,但它仅能选中section元素内的目标div:

#task-6 section div:not(:not(:first-child):not(:last-child))

恳请提供帮助,非常感谢。


内容的提问来源于stack exchange,提问作者Noah Zemljic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 19:40:30