1

nthオブジェクトのグループ内の 3 つの要素ごとに 1 つを選択する方法を理解しようとしています。

マークアップが次のように構成されている場合:

<div class="all-items">
  <div class="block">
    <a href="the-link">
      <div class="image-list">
        <div class="drop-shadow curved curved-hz-1">
          <img src="an-image.png" />
        </div>
      </div>
    </a>
  </div>

  <!-- then this repeats to show all the images -->
  <div class="block">
    <a href="the-link">
      <div class="image-list">
        <div class="drop-shadow curved curved-hz-1">
          <img src="an-image.png" />
        </div>
      </div>
    </a>
  </div>

  <!-- ... etc. -->

</div> <!-- end div class "all-items" -->

img内部の画像のグループで3番目ごとに選択するにはどうすればよい<div class="all-items">ですか?

4

2 に答える 2

3
div.block:nth-child(3n) img { /*your css here*/ }

div の 3 ブロックを選択してから、その中の画像を選択しています。

于 2013-08-05T22:14:16.347 に答える
1

.blockこれにより、の画像が 3 分の 1 ずつ選択されます。

.block:nth-child(3n) img {
    /* styles */
}

デモ: http://jsfiddle.net/sC8Ne/

于 2013-08-05T22:15:14.240 に答える