2017-02-01 5 views
3

私はこれを理解しようとしていましたが、成功しませんでした - これは動作するプレースホルダとして持ちますが、 ...css nth-child、3回ごと+ 1、すなわち:4,7,10,13など

.customField:nth-child(4), 
.customField:nth-child(7), 
.customField:nth-child(10), 
.customField:nth-child(13), 
.customField:nth-child(16) { 
    clear: both; 
} 

nth-childの声明にはどうすればいいですか?

+0

非常に近いです。 – BoltClock

答えて

7

すべての3番目の子は3nですが、4番目に開始するには4をオフセットとして使用してください。

div:nth-child(3n + 4) { 
 
    color: red; 
 
}
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div> 
 
<div>asdf</div>

+0

私はそれを試みた - しかし、再訪し、これはトリック、ありがとう! –

2

私は:nth-child(3n+4)が働くだろうと信じています。

与えられた値がnの場合、一般形式は:nth-child(an+b)です。ここで、nは正数またはゼロです。

関連する問題