首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何选择没有:n个伪类的元素的中间子类

如何选择没有:n个伪类的元素的中间子类
EN

Stack Overflow用户
提问于 2022-09-25 09:50:45
回答 1查看 46关注 0票数 -1

我目前正在为高中学生的网络发展区域锦标赛做准备.准备工作是锦标赛网站要解决的问题之一。我有以下HTML代码:

代码语言:javascript
复制
<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>

我的目标是选择带有标记为marbledata-target类的div,但如下所示:

  • I不允许使用这些CSS伪类或CSS选择器:

代码语言:javascript
复制
- `:nth-child`
- `:nth-last-child`
- `:nth-of-type`
- `:nth-last-of-type`
- `[data-target]`
- nor any use of `+` or `~`

  • 只允许一个选择器。

我尝试了下面的选择器,但是它只选择了部分元素中的div

代码语言:javascript
复制
#task-6 section div:not(:not(:first-child):not(:last-child))

你能帮帮我吗。非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-25 10:03:09

您尝试过的选择器-

代码语言:javascript
复制
#task-6 section div:not(:not(:first-child):not(:last-child))

它显式地表示要对div内部区段元素进行工作。

只需从其中移除部分,它应该适用于每个元素

代码语言:javascript
复制
#task-6 div:not(:not(:first-child):not(:last-child))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73843558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档