W3C验证错误:span元素

时间:2014-05-06 08:00:12

标签: html validation

当我验证我的页面时,我遇到以下错误:

  

在此上下文中,元素跨度不允许作为元素ul的子元素。   (抑制此子树中的更多错误。)

这是我的HTML标记:

<nav>
<ul>
    <li class="nav-home">
        <a href="index.html" title="Home">Home</a>
    </li>
    <span class="solidus"> &#47;</span>
    <li class="nav-paints">
        <a href="paints.html" title="Paints">Paints</a>
    </li>
    <span class="solidus"> &#47;</span>
    <li class="nav-non-paints">
        <a href="non-paints.html" title="Non-paints" class="active">Non-paints</a>
    </li>
    <span class="solidus"> &#47;</span>
    <li class="nav-advies">
        <a href="advies.html" title="Advies">Advies</a>
    </li>
    <span class="solidus"> &#47;</span>
    <li class="nav-training">
        <a href="training.html" title="Training">Training</a>
    </li>
    <span class="solidus"> &#47;</span>
    <li class="nav-afvalbeheer">
        <a href="afvalbeheer.html" title="Afvalbeheer">Afvalbeheer</a>
    </li>
</ul>
</nav>

我尝试用常规div替换跨度并将它们放在内联中,但是,这显然也是不允许的。有关如何解决此错误的任何想法?

2 个答案:

答案 0 :(得分:2)

您应该将span放在li内,如下所示:

<li class="nav-home">
    <a href="index.html" title="Home">Home</a>
    <span class="solidus"> &#47;</span>
</li>

这完全有效。

答案 1 :(得分:1)

问题是<span>元素没有嵌套在任何其他标记和任何级别中,因为您将<span>元素放在列表中但不包含任何<li>元素。所以列表正在爆发!

如果可以,请尝试将其放在<li>元素内的任何元素中,例如!

<nav>
<ul>
    <li class="nav-home">
        <a href="index.html" title="Home">Home</a>
        <span class="solidus"> &#47;</span>
    </li>
    <li class="nav-paints">
        <a href="paints.html" title="Paints">Paints</a>
    </li>
    <span class="solidus"> &#47;</span>
    <li class="nav-non-paints">
        <a href="non-paints.html" title="Non-paints" class="active">Non-paints</a>
        <span class="solidus"> &#47;</span>
    </li>
    <li class="nav-advies">
        <a href="advies.html" title="Advies">Advies</a>
        <span class="solidus"> &#47;</span>
    </li>
    <li class="nav-training">
        <a href="training.html" title="Training">Training</a>
        <span class="solidus"> &#47;</span>
    </li>
    <li class="nav-afvalbeheer">
        <a href="afvalbeheer.html" title="Afvalbeheer">Afvalbeheer</a>
        <span class="solidus"> &#47;</span>
    </li>
</ul>
</nav>