Ive got color swatches on my product list template page that show the available colors for the product. On mobile, I want to only display the first 2 , and then provide the “more accessible” button, which jumps to a specific product page. On the desktop, I want to display the first 4 , and then provide the “more accessible” button, which will also take you to the product page.
I can display and hide the colors available on any viewport (using css), however how would I make the logic of variables when I need to provide a “more accessible” button on the desktop and mobile device?

HTML:
<!— Product —>
<div class="product">
<div class="colour-swatches">
<ul>
<li class="swatch">Red</li>
<l class="swatch"i>Blue</li>
<li class="swatch">Green</li>
<li class="swatch">Orange</li>
<li class="swatch">Yellow</li>
<li class="swatch">Black</li>
<li class="swatch">Lime</li>
</ul>
</div>
</div>
CSS
Li.swatch {
&:nth-child(-n+2) {
display: block !important;
visibility: visible !important;
}
@media (min-width: 600px) {
&:nth-child(-n+3) {
display: block !important;
visibility: visible !important;
}
}
}
source
share