<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
</ul>
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
</ul>
<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>
//定义mixin
@mixin n-items($n) {
  &:first-child:nth-last-child(#{$n}),
  &:first-child:nth-last-child(#{$n}) ~ & {
    @content; 
  }
}
li {
  @include n-items(4){
    background-color:#d71076;
    position: relative;

    &:after {
      content:"";
      position: absolute;
      width: 18px;
      height: 18px;
      right: -3px;
      top: -3px;
      background: url("https://www.w3cplus.com/sites/default/files/blogs/2015/1507/list-right.png") no-repeat center;
    }
  }
}

/*base style*/
ul {
  text-align: center;
  margin: 20px;
  padding: 0;
  list-style: none outside none;
}
li {
  display: inline-block;
  width: 48px;
  height: 48px;
  line-height: 48px;
  border-radius: 4px;
  color: #fff;
  background-color: #d8beb6;
  margin: 5px;
  font-size: 1.2em;
  font-family: Arial;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.