これは、リーニュごとに1からラインごとに5までのcssチェッカーボード(ダミエ)のレスポンシブバージョンです。
http://jsfiddle.net/Choufourax/pb09o5fa/1/
CSS
div.grid {
display: grid;
}
div.grid > div {
color: red;
height: 200px;
background-color: gray;
/* comment these 3 lines if you don't need to center content */
display: flex;
align-items: center;
justify-content: center;
}
/* Default => 1 per ligne */
@media only screen and (max-width: 600px) {
div.grid > div:nth-child(odd) {
background-color: black;
}
}
/* 50% => 2 per ligne */
@media only screen and (max-width: 840px) and (min-width: 600px) {
div.grid {
grid-template-columns: 1fr 1fr;
}
div.grid > div:nth-child(4n+1), div.grid > div:nth-child(4n+4) {
background-color: black;
}
}
/* 33% => 3 per ligne */
@media only screen and (max-width: 1024px) and (min-width: 840px) {
div.grid {
grid-template-columns: 1fr 1fr 1fr;
}
div.grid > div:nth-child(6n+1), div.grid > div:nth-child(6n+3), div.grid > div:nth-child(6n+5) {
background-color: black;
}
}
/* 25% => 4 per ligne */
@media only screen and (max-width: 1140px) and (min-width: 1024px) {
div.grid {
grid-template-columns: 1fr 1fr 1fr 1fr;
}
div.grid > div:nth-child(8n+1), div.grid > div:nth-child(8n+3), div.grid > div:nth-child(8n+6), div.grid > div:nth-child(8n+8) {
background-color: black;
}
}
/* 20% => 5 per ligne */
@media only screen and (min-width: 1141px) {
div.grid {
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
}
div.grid > div:nth-child(10n+1), div.grid > div:nth-child(10n+3), div.grid > div:nth-child(10n+5), div.grid > div:nth-child(10n+7), div.grid > div:nth-child(10n+9) {
background-color: black;
}
}
HTML:
<div class="grid">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>