html - nth-child selector not working -


i need hide border 4, 3, 2 wrapper based on screen size.

i show 4, 3, 2 , 1 items in row based on screen size.

@media( min-width:1000px){   #news-tab > div > .news-tab-item-wrapper:nth-child(2n+1){    border-right:2px solid #fff;    background:red;   } } 

based on above css should not show border last element, not able target it. may using wrong reference in case.

<div id="news-tab" class="tab-pane">   <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">     <div class="news-tab-item-wrapper">        <span>this news title</span>       <a href="#">read more</a>     </div>   </div>   <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">     <div class="news-tab-item-wrapper">        <span>this news title</span>       <a href="#">read more</a>     </div>   </div>   <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">     <div class="news-tab-item-wrapper">        <span>this news title</span>       <a href="#">read more</a>      </div>   </div>   <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">     <div class="news-tab-item-wrapper">        <span>this news title</span>       <a href="#">read more</a>     </div>   </div> </div> 

fiddle sample :http://jsfiddle.net/zvwqnwu2/5/

working fiddle: http://jsfiddle.net/zvwqnwu2/9/

there few errors in code posted in question:

  1. there no element class news-tab-item-wrapper-w.
  2. even if above typo, there 1 element class news-tab-item-wrapper also. others have news-tab-wrapper.
  3. if typo , have same class, selector still not work because each such item 1 , child parent.

for case, believe need below selector. selector select element class news-tab-item-wrapper under div element not first child of parent.

#news-tab > div:nth-child(n+2) > .news-tab-item-wrapper{      border-right:2px solid blue;      background:red; } 

if want target last element .news-tab-item-wrapper class use either of below selector current markup.

#news-tab > div:last-of-type > .news-tab-item-wrapper{      border-right:2px solid blue;      background:red; } 

or

#news-tab > div:last-child > .news-tab-item-wrapper{      border-right:2px solid blue;      background:red; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -