add clear:bothonly the 3n+1element from the fourth element. remove the border for li, which after the fourth element from the last
ul {
display: block;
width: 100%;
margin: 0;
padding: 0
}
li {
display: block;
width: 33%;
height: 120px;
float: left;
margin: 0;
padding: 0;
border-bottom: #666 1px solid;
background: #fcc
}
li:nth-child(3n+1) {
clear:both;
}
li:nth-last-child(4) ~ li:nth-child(3n+1), li:nth-last-child(4) ~ li:nth-child(3n+1) ~ li {
border-bottom: 0px;
}
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
</ul>
Run codeHide resultThis code will remove the lower border of the lower border, no matter how much you have
Explaination: -
li:nth-last-child(4) will be the fourth element of the last (border deletion should begin after this element).
, li:nth-last-child(4), li:nth-child(3n+1) (, 4,7,10...), (li:nth-child(3n+1)). ~ - siblings.