How to style all other elements in the list in bold?

I want to create my list as follows:

  • List item
  • List item
  • List item
  • List item
  • List item

^^ you see here the first is bold, the second is normal, the third is bold, etc.

I want to do the same thing dynamically on my list.

+6
source share
4 answers

Use the css3 nth-child selector:

 ol>li:nth-child(odd){ font-weight:bold; }​ 

Here: http://jsfiddle.net/FwTBU/

+18
source

Something like this should do the job

 ul.zebra li:nth-child(odd), ol.zebra li:nth-child(odd) { font-weight: bold; } 

And your markup will be

 <ul class="zebra"> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> </ul> 

or

 <ol class="zebra"> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> </ol> 
+1
source
 ol li { font-weight:normal } ol li:nth-child(odd){ font-weight:bold; } 
0
source
 li:nth-child(odd) { font-weight:bold } li:nth-child(even) { font-weight:normal } 
0
source

Source: https://habr.com/ru/post/909732/


All Articles