<div class="wrapper">
<h3>子要素の数が少なくとも5個、最大で7個の場合にのみスタイリング</h3>
<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>
</ul>
<ul>
<li>1.</li>
<li>2.</li>
<li>3.</li>
<li>4.</li>
<li>5.</li>
<li>6.</li>
</ul>
<ul>
<li>1.</li>
<li>2.</li>
<li>3.</li>
<li>4.</li>
<li>5.</li>
<li>6.</li>
<li>7.</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>
</div>
<!-- End of .wrapper -->
ul li:nth-last-child(n+5):nth-last-child(-n+7):first-child,
ul li:nth-last-child(n+5):nth-last-child(-n+7):first-child ~ li {
background-color: orange;
}
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
p {
margin-top: 0;
}
ul {
margin: 0.3125rem 0.3125rem 0.625rem;
}
li {
display: inline-block;
width: 4rem;
height: 4rem;
list-style-type: none;
margin: 0.3125rem;
background-color: royalblue;
color: white;
font-size: 2rem;
text-align: center;
line-height: 2;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.