无法弄清楚原因:nth-​​of-type不起作用

时间:2013-04-22 17:20:51

标签: css

我正在尝试在我的div库中选择每个第四张图片。我似乎无法弄清楚为什么我不能选择它。

#gallery img:nth-of-type(4n){
   border: 5px solid #000;
}

我尝试过其他一些想法,但没有成功。任何人都可以帮助我,并向我解释为什么这不是在我的div画廊中选择每个第四个图像?提前谢谢。

    <div id="gallery">

  <a href="/system/images/series_uploads/5/original/ankara_5602p_alabaster.jpg?1330114093" rel="lightbox['gallery']">
    <img alt="" src="/system/images/series_uploads/5/gallery/ankara_5602p_alabaster.jpg?1330114093" title="Ankara" />
    <div class="gallery-text">
      <h3>Ankara</h3>
      <p>Porcelain</p>
    </div>
  </a>

  <a href="/system/images/series_uploads/6/original/ankara_5624p_noce.jpg?1330114095" rel="lightbox['gallery']">
    <img alt="" src="/system/images/series_uploads/6/gallery/ankara_5624p_noce.jpg?1330114095" title="Ankara" />
    <div class="gallery-text">
      <h3>Ankara</h3>
      <p>Porcelain</p>
    </div>
  </a>

  <a href="/system/images/series_uploads/7/original/ashton_23931_smokey_beige_.jpg?1330114250" rel="lightbox['gallery']">
    <img alt="" src="/system/images/series_uploads/7/gallery/ashton_23931_smokey_beige_.jpg?1330114250" title="Ashton" />
    <div class="gallery-text">
      <h3>Ashton</h3>
      <p>Porcelain</p>
    </div>
  </a>

  <a href="/system/images/series_uploads/8/original/ashton_23942_camel_haze_entry.jpg?1330114251" rel="lightbox['gallery']">
    <img alt="" src="/system/images/series_uploads/8/gallery/ashton_23942_camel_haze_entry.jpg?1330114251" title="Ashton" />
    <div class="gallery-text">
      <h3>Ashton</h3>
      <p>Porcelain</p>
    </div>
  </a>

  <a href="/system/images/series_uploads/9/original/ashton_23942_camel_haze_lr.jpg?1330114252" rel="lightbox['gallery']">
    <img alt="" src="/system/images/series_uploads/9/gallery/ashton_23942_camel_haze_lr.jpg?1330114252" title="Ashton" />
    <div class="gallery-text">
      <h3>Ashton</h3>
      <p>Porcelain</p>
    </div>
  </a>

  <a href="/system/images/series_uploads/10/original/berkshire_25525_oak.jpg?1330115116" rel="lightbox['gallery']">
    <img alt="" src="/system/images/series_uploads/10/gallery/berkshire_25525_oak.jpg?1330115116" title="Berkshire" />
    <div class="gallery-text">
      <h3>Berkshire</h3>
      <p>HDP &ndash; High Definition Porcelain</p>
    </div>
  </a>

  <a href="/system/images/series_uploads/11/original/berkshire_25585_walnut_famousdaves01.jpg?1330115118" rel="lightbox['gallery']">
    <img alt="" src="/system/images/series_uploads/11/gallery/berkshire_25585_walnut_famousdaves01.jpg?1330115118" title="Berkshire" />
    <div class="gallery-text">
      <h3>Berkshire</h3>
      <p>HDP &ndash; High Definition Porcelain</p>
    </div>
  </a>
</div>

1 个答案:

答案 0 :(得分:4)

他们不是兄弟姐妹,这就是你应该使用

的原因
#gallery a:nth-of-type(4n) img{
   border: 5px solid #000;
}