I have a list of items with a data attribute of boolean value. List is sorted in a way, that items with true
will always come first, false
will be placed after them (it's possible that all elements will have true
or false
as well). I want to display only two middle elements - last of true
and first of false
ones. If all elements have the same value of attribute, then only single element will be displayed.
Here's example HTML:
<div class="container">
<div class="item" data-attr="true">1<div>
<div class="item" data-attr="true">2<div>
<div class="item" data-attr="false">3<div>
<div class="item" data-attr="false">4<div>
</div>
I know how to select items by attribute:
.container .item[data-attr="true"],
.container .item[data-attr="false"] {
display: none;
}
but I don't know how to select all except first or last of those preselected items.
Expected visible output would be this:
<div class="container">
<div class="item" data-attr="true">2<div>
<div class="item" data-attr="false">3<div>
</div>
I can probably add some more JS code, so that those items receive additional class or another data attribute, but I wonder if it's possible with just CSS.