Can not have an ul inside an ol in html

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 04:58:01

问题


I get the following validation error when I tested my HTML.

Please look at the attached image for the HTML code.

"Element ul not allowed as child of element olin this context."

回答1:


This is because the content model for <ol> (and <ul> actually) is zero or more li elements

These two tags actually can't contain anything other than <li> tags or nothing at all. If you have <ol><ul> browsers will automatically close the <ol> tag before beginning the <ul> (well, the good ones).

I think your intent is to have:

<ol>
    <li>
        <ul>

The <ul> can be contained inside of an <li> that is a child of the <ol>.




回答2:


This is because you should wrap the internal <ul> in a list <li> item:

<ul><li>text</li>....</ul>

becomes:

<li><ul><li>text</li>....</ul></li>



回答3:


You should do these

<ol>
  ...
  <li>title</li>
  <li><!-- add this -->
    <ul><!-- your ul put here -->
    ...
    </ul>
  </li><!-- add this -->
  ...
</ol>

PS. In some case use original code better than image.




回答4:


Try to wrap <ul> part into a <li> tag.



来源:https://stackoverflow.com/questions/15870444/can-not-have-an-ul-inside-an-ol-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!