-1

I have the following code. I want to have different background color for blockquotes having innertext Text2 & Text4, and different background for blockquotes having innertext Text1 & Text3. Need help.

<div class="quotes">
<blockquote>Text1</blockquote>
<blockquote>Text2</blockquote>
<blockquote>Text3</blockquote>
<blockquote>Text4</blockquote>
</div>
Arslan Bhatti
  • 193
  • 1
  • 2
  • 12

2 Answers2

4

You can use nth-child selector:

Ex-

blockquote:nth-child(1){ /*for first blockquote */
  background-color: red;
}
blockquote:nth-child(2){ /*for second blockquote */
   background-color: red;
}

As per your comment:

You can use odd and even too:

blockquote:nth-child(odd){
   background-color: red;
}


blockquote:nth-child(even){
   background-color: red;
}
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
1

Try this:

blockquote:nth-child(even){
  background-color: red;
}
blockquote:nth-child(odd){
   background-color: blue;
}
AmanVirdi
  • 1,667
  • 2
  • 22
  • 32