Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style every other item in a list as bold?

Tags:

html

css

I want to style my list like this:

  1. List item
  2. List item
  3. List item
  4. List item
  5. List item

^^ you see here the first is bold, second is normal, third is bold, and so on.

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

like image 522
Faisal Avatar asked Mar 01 '12 12:03

Faisal


People also ask

How do I make a list bold in elements?

To bold the text in HTML, use either the strong tag or the b (bold) tag. Browsers will bold the text inside both of these tags the same, but the strong tag indicates that the text is of particular importance or urgency. You can also bold text with the CSS font-weight property set to “bold.”

How do I style a specific list in CSS?

To specify the style for a list, use the list-style property to specify the type of marker. The selector in your CSS rule can either select the list item elements li , or it can select the parent list element ul so that its list elements inherit the style.

How do you style the UL list to one line?

The quickest way to display a list on a single line is to give the <li> elements a display property value of inline or inline-block . Doing so places all the <li> elements within a single line, with a single space between each list item.


2 Answers

Use css3 selector nth-child:

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

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

like image 65
welldan97 Avatar answered Sep 22 '22 11:09

welldan97


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 would 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>

ul.zebra li:nth-child(odd),
ol.zebra li:nth-child(odd)
{
    font-weight: bold;
}
<ul class="zebra">
    <li>List item</li>
    <li>List item</li>
    <li>List item</li>
    <li>List item</li>
</ul>


<ol class="zebra">
    <li>List item</li>
    <li>List item</li>
    <li>List item</li>
    <li>List item</li>
</ol>
like image 40
Joe Avatar answered Sep 20 '22 11:09

Joe