kamaci kamaci - 22 days ago 5
HTML Question

Using ul Inside ol

I'm trying to write a valid HTML however this fails:

<ol>
<li>First</li>
<li>Second</li>
<ul>
<li>First of second</li>
</ul>
</ol>


This fails at when generating javadoc. It says:

error: tag not allowed here: <ul>


Desired output should be like that:


  1. First

  2. Second


    • First of second




Isn't it valid to define ul inside ol?

Answer

Wrap the ul in an li, as the only valid children of ul and ol are li.

If you don't want the bullet to show, you can exclude them via a class

HTML:

<ol>   
  <li>First</li>   
  <li>Second</li>
  <li class="no-bullet">
    <ul>
      <li>First of second</li>
    </ul>
  </li>
  <li>Third</li>
</ol>

CSS:

.no-bullet {
  list-style: none;
}

fiddle

If you don't want to use CSS, either use inline-styles or the type attribute:

<li style="list-style: none;">Item</li>

OR

<li type="none">Item</li>
Comments