Reputation: 652
Can you use nth-child to style , not for odd, even but for various out of order items ?
I want to style 1,3,7,8 , so how would i do that ?
Demo http://jsfiddle.net/nTZrg/50/
<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>
</ul>
Upvotes: 0
Views: 109
Reputation: 1386
if it's random numbers I think you need javascript here's a jquery implementation http://jsfiddle.net/nTZrg/52/
<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>
</ul>
var array = [1, 3, 7, 8]
for (i=0; i < array.length; i++) {
$('ul li').eq(array[i]).prev().addClass('blue')
}
.blue {
background-color:blue;
color: white;
}
Upvotes: 0
Reputation: 50189
Provided that 1,3,7,8 are random and not some sort of pattern it's fairly simple:
ul li:nth-child(1),
ul li:nth-child(3),
ul li:nth-child(7),
ul li:nth-child(8){
background-color:blue;
color: white;
}
Upvotes: 4