css - How to select every two elements alternating? -
i select every 2 rows , alternate , repeat in pattern. how can using css?
for example....
blue rows: 1,2,5,6,9,10
red rows: 3,4,7,8
ul{ list-style-type: none; color: white; } li:nth-of-type(odd){ background-color:blue; } li:nth-of-type(even){ background-color:red; } <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> <li>9</li> <li>10</li> </ul edit: forgot add key point, sorry! repetition used in ng-repeat of unknown length go on forever. won't able explicity type every 2 in css.
the logical rules doing following.
- select every fourth, , next one. color in red.
- select every fourth , move 2 ahead, , next one. color in blue.
"move next one" can done using + combinator (next sibling).
ul{ list-style-type: none; color: white; } li:nth-of-type(4n+3), li:nth-of-type(4n+3) + * { background-color:blue; } li:nth-of-type(4n+1), li:nth-of-type(4n+1) + * { background-color:red; } <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> <li>9</li> <li>10</li> </ul or, hamms suggested in comments section below, can use 4n+1 , 4n+2 blue; , 4n+3 , 4n red.
Comments
Post a Comment