0

I have this small problem, I am building a nested ordered list, and I want to be able to customize the styles of top level elements (note that bold is both on the counter and text).

1. AAA

1.1 Lorem ipsum

1.2 Lorem ipsum

1.3 Lorem ipsum

2. BBB

2.1 Lorem ipsum

2.2 Lorem ipsum

2.3 Lorem ipsum

The problem I have encountered is that if I apply any <h> tag for the top level elements of the list, the counter breaks.

Without the <h3> tags counters work properly, but without <h3> I am unable to style top level elements of the list.

How can I get both working counter and styled top level elements?

Sample here:

#test li {
  font-size: 16px;
  padding: 2px 0;
  display: block;
  margin-left: 10px
}

#test h3 {
  display: inline-block;
  padding: 0 0 5px 0;
}

#test ol, ul {
  list-style-type: decimal;
}

#test li:before {
  content: counters(item, ".") " ";
  counter-increment: item
}

#test ol {
  counter-reset: item;
  margin: 0
}

#test h3>li {
  font-size: 26px;
}
    <div id="test">
    
    <ol>
       
    <h3><li>AAAA</h3>
    <ol>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    </ol>
    </li>
    
        
    <h3><li>BBBB</h3>
    <ol>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    </ol>
    </li>
    
    <h3><li>CCCC</h3>
    <ol>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    </ol>
    </li>
    
    </ol>
    </div>
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Andy Andy
  • 279
  • 4
  • 7
  • 17

3 Answers3

4

You have bad formatting on your "top-level" list-elements. the < li > attribute should be outside < h3 > attribute. Check out this pen: http://codepen.io/anon/pen/jqPrWb

<body>
<div id="test">

    <ol>

      <li>
        <h3>AAAA</h3>
    <ol>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    </ol>
    </li>


    <li>
      <h3>BBBB</h3>
    <ol>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    </ol>
    </li>

  <li>  
    <h3>CCCC</h3>
    <ol>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    <li><a href=”#”>Lorem ipsum.</a></li>
    </ol>
   </li>

    </ol>
    </div>
</body>

Edit: Use CSS :before... Check out new pen http://codepen.io/anon/pen/jqPrWb

ol :before{
  font-size: 40px;
}

This will set the font-size of all numbers in < ol >... Using classes, you can set it on specific levels of your list!

chrisv
  • 724
  • 6
  • 18
  • Chek out my new pen! :) Using the :before property will probably help you out! – chrisv Mar 02 '16 at 13:45
  • 1
    I was waiting to see your next update mate because you had got part of the answer correct but have proceeded to add my own answer because I felt the other part is still not completely answered. Didn't feel comfortable modifying your answer to include my version. But a upvote from me for addressing a very key part of the problem :) – Harry Mar 02 '16 at 13:57
  • 1
    Teamwork I guess! The important thing is helping out this guy! :P – chrisv Mar 02 '16 at 13:59