我如何选择其他每个孩子和邻近的孩子?

发布于 2025-02-03 01:28:54 字数 331 浏览 0 评论 0原文

为所需的结果附加了

图像10 为所需的结果附加了图像。那么,如何使用nth-child或其他东西选择这些呢?它会像这样...

(1)(2) (3)(4) (5)(6) (7)(8) (9)(10)

Image attached for desired result

I want to select in order 2,3 then 6,7 and then 10 Image attached for desired result. So How do I select these with nth-child or something else? It'll go something like this...

(1)(2)
(3)
(4)
(5)(6)
(7)
(8)
(9)(10)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷鸟归林 2025-02-10 01:28:54

您可以使用以下方式解决此问题:nth-​​child使用两个公式,一个用于均匀数字,一个用于偶数。这是我建议的一个工作示例:

<style>
    li:nth-child(4n - 2), li:nth-child(4n - 1) { color: red; }
</style>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
    <li>10</li>
</ul>

4n部分提供了您要寻找的“其他偶数/奇数”部分:它将每4个项目选择一个。 -1-2偏移此间隔以匹配所需的数字。使用Offsets +10时,您可以获得逆行为(选择1、4、5、8、9等)。

You could solve this with :nth-child using two formulas, one for the even numbers and one for the even ones. This is a working example of my suggestion:

<style>
    li:nth-child(4n - 2), li:nth-child(4n - 1) { color: red; }
</style>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
    <li>10</li>
</ul>

The 4n part provides the "every other even/odd" part you're looking for: it will select one every 4 items. The -1 and -2 offset this interval to match the numbers you want. You could get the inverse behaviour (select 1, 4, 5, 8, 9, etc) when using offsets +1 and 0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文