1

I have problem with css styling of my Ordered List.

I have my HTML code:

ol {
  counter-reset: item
}

li {
  display: block
}

li:before {
  content: counters(item, ".")" ";
  counter-increment: item
}
<ol>
  <li class="sub">one</li>
  <li class="">two
    <ol>
      <li class="small">two.one</li>
      <li class="small">two.two</li>
      <li class="small">two.three</li>
    </ol>
  </li>
  <li>three
    <ol>
      <li>three.one</li>
      <li>three.two
        <ol>
          <li>three.two.one</li>
          <li>three.two.two</li>
        </ol>
      </li>
    </ol>
  </li>
  <li>four</li>
</ol>

And I need to hide number value from 1 one, 2 two, 3 three and 4 four Someone has idea, how to do that, please?

Ivar
  • 6,138
  • 12
  • 49
  • 61
Matus Vrsansky
  • 83
  • 1
  • 10

1 Answers1

0

You can mimick the behavior you are looking for by setting the font-size to 0px and this would make the element be counted by the counter property while hiding it.

.hide { 
    font-size: 0px;
}
<ol>
    <li>one</li>
    <li>two
        <ol>
            <li>two.one</li>
            <li class="hide">two.two</li>
            <li>two.three</li>
        </ol>
    </li>
    <li>three
        <ol>
            <li>three.one</li>
            <li>three.two
                <ol>
                    <li>three.two.one</li>
                    <li>three.two.two</li>
                </ol>
            </li>
            <li class="hide">three.three</li>
            <li>three.four</li>
        </ol>
    </li>
    <li>four</li>
</ol>

Source: CSS counter on hidden submenu

nsayer
  • 799
  • 2
  • 8
  • 21
  • Nice solutions, but you know, when It will be implemented on
  • elements with the "one", "two" , "three", that text will be also hidden... but I need to hide only number before "one", "two", "three"....
  • – Matus Vrsansky Jun 07 '18 at 09:53