css获取下一个元素,css选择器获得2个元素(css selector get 2 elements)

css选择器获得2个元素(css selector get 2 elements)

我需要选择两个元素,跳过接下来的两个元素,选择两个元素等。

例如,假设我有10个元素:

element1
element2
element3
element4
element5
element6
element7
element8
element9
element10

我想选择元素1,2,5,6,9和10。

有没有办法利用nth-child或类似的东西实现这一目标?

I need to select two elements, skip the next two elements, select two elements, etc.

For example, assuming I have 10 elements:

element1
element2
element3
element4
element5
element6
element7
element8
element9
element10

I want select the elements 1, 2, 5, 6, 9, and 10.

Is there any way, utilizing nth-child or similar, to achieve this?

原文:https://stackoverflow.com/questions/33681069

更新时间:2020-01-10 16:01

最满意答案

组合选择器以便为每四个元素选择第一个/第二个元素。

.container > .el:nth-child(4n+1),

.container > .el:nth-child(4n+2) {

color: red;

}

.container > .el:nth-child(4n+1),

.container > .el:nth-child(4n+2) {

color: red;

}

element1
element2
element3
element4
element5
element6
element7
element8
element9
element10

Combine selectors in order to select the first/second element for each four elements.

.container > .el:nth-child(4n+1),

.container > .el:nth-child(4n+2) {

color: red;

}

.container > .el:nth-child(4n+1),

.container > .el:nth-child(4n+2) {

color: red;

}

element1
element2
element3
element4
element5
element6
element7
element8
element9
element10

相关问答

一种可能的解决方案是选择具有匹配类名的所有元素,然后选择具有正确样式属性的第一个元素。 你还没有说过测试编写的语言,但C#中的一个例子是: IWebElement element = driver.FindElements(By.CssSelector("ul.textboxlist-bits")).First(e => e.GetAttribute("style").Contains("background-color: transparent;")); A possible solution

...

你使用两者(两者之间没有空格 ) .checked.featured{

// ...

}

参考: http : //www.w3.org/TR/selectors/#class-html 例 div{margin:1em;padding:1em;}

.checked{color:green;}

.featured{border:1px solid #ddd;}

.checked.featured{

font-weight:bold;

}

...

如果我正确地阅读了规范 ,没有。 您可以在元素上匹配元素中的属性名称,以及元素中命名属性的值。 但是,我没有看到匹配内容的内容。 If I read the specification correctly, no. You can match on an element, the name of an attribute in the element, and the value of a named attribute in an element. I don't see anything fo

...

:disabled伪选择器仅适用于输入元素。 对于div,使用div[disabled]来应用css 使用 div[disabled] {

opacity: 0.4;

filter: alpha(opacity=40); /* For IE8 and earlier */

}

演示 input:enabled {

background: #ffff00;

}

input:disabled {

background: #dddddd;

}

div[d

...

一种方法是使用嵌套的标签,而不是使用background-image 。 然后,您可以设置background-position ,使background-image位于正确的位置,然后将所需的样式应用于li本身。 例如,你可以这样做: li {

border: 1px solid black;

margin: 10px;

padding: 10px;

float: left;

background-repeat:no-repeat;

ba

...

您可以使用querySelector()方法,该方法始终返回查询中的第一个元素: var element = document.querySelector('input.myInput');

jQuery没有直接的等价物,所以你必须使用[0]索引。 You can use the querySelector() method, which always returns the first element from a query: var element = document.querySele

...

答:没有。 但是你总是可以选择JQuery: $('#id').nextUntil('#id2')

请记住, .nextUntil方法选择中间的所有元素, 不包括。 要选择包含两个元素的元素,请使用: $('#id').nextUntil('#id2').andSelf().add('#id2')

.siblings * {

display: block;

border: 2px soli

...

只要摆脱p p.hometown说你只想将该规则应用于使用该类的

元素 .hometown {

background: yellow;

}

将该类应用于class =“hometown”的所有元素。 p.hometown, div.hometown {

background: yellow;

}

将类应用于

元素 Just get rid of the p p.hometown says you only want to apply that rule t

...

你可以试试: "div.select-me :not(script)"

You can try: "div.select-me :not(script)"

为此使用:nth-child()伪类 。 组合选择器以便为每四个元素选择第一个/第二个元素。 这里的例子 .container > .el:nth-child(4n+1),

.container > .el:nth-child(4n+2) {

color: red;

}

.container > .el:nth-child(4n+1),

.container > .el:nth-child(4n+2) {

color: red;

}

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值