I have a few random blocks. Whenever a block falls in the new row, I am making it look different. When the user clicks on a button, I hide few blocks by display:none
, and the problem occurs. The nth-child
selector also counts hidden elements.
Is there way to ignore those specific blocks, so that again every row has a different style? This is an example of a similar scenario.
$('.hide-others').click(function () {
$('.css--all-photo').toggleClass('hidden');
})
.board-item--inner {
height:200px;
background:tomato;
text-align:center;
color:#fff;
font-size:33px;
margin-bottom:15px;
border:2px solid tomato;
}
@media (min-width:768px) and (max-width:991px) {
.board-item:nth-child(2n+1) .board-item--inner {
border:2px solid #000;
background:yellow;
color:#000;
}
}
@media (min-width:992px) and (max-width:1199px) {
.board-item:nth-child(3n+1) .board-item--inner {
border:2px solid #000;
background:yellow;
color:#000;
}
}
@media (min-width:1200px) {
.board-item:nth-child(4n+1) .board-item--inner {
border:2px solid #000;
background:yellow;
color:#000;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div class="form-group">
<button class="btn btn-info hide-others" type="button">Hide others</button>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item">
<div class="board-item--inner">1</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item">
<div class="board-item--inner">2</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item css--all-photo">
<div class="board-item--inner">3</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item">
<div class="board-item--inner">4</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item">
<div class="board-item--inner">5</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item css--all-photo">
<div class="board-item--inner">6</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item">
<div class="board-item--inner">7</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item css--all-photo">
<div class="board-item--inner">8</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item">
<div class="board-item--inner">9</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item">
<div class="board-item--inner">0</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3 board-item photos-board-item">
<div class="board-item--inner">10</div>
</div>
</div>
<div>
Simply go through the snippet or EXTERNAL FIDDLE, and you'll get my question.
I am specifically looking for a pure CSS solution. Please provide a fiddle for your answers! And I cannot remove those blocks permanently, my user has the option to filter files on button click, that is why hidden and shown scenario.
clear:float
in every new row, to prevent it flowing to wrong direction – Gratingdisplay:none
using specific css class) – Gratingnth-child(count)
– Gratinguser_a
anduser_b
as class names then you can use the CSS:nth-child
selector the way you want to. – Dichromic:nth-of-type
and:nth-child
are going to count all of the elements of the same type regardless of whether they are hidden or not. There might not be a CSS only solution to this problem. – Dichromic.board-item:not(.hidden):nth-of-type(count) .board-item--inner
and that didn't work either. – Flintshirenth-child
on the shown class? – Opinionative:not([style='display: none'])
. – Pad