为什么<a href=""> is not allowed as child of </a> <figure> <a href="">

时间:2015-12-14 00:15:53

标签: html5 validation syntax-error

Here is a bit of code that w3.org doesn't validate:

<figure class="image">
    <img src="#" alt="#">
    <figcaption>
        <small>Cabinet Artwork</small>
        <br>
        Pretty in Pink in Mt Albert
    </figcaption>
    <a href="#" class="more"></a>
</figure>

The validator throws an error, stating that "Element a not allowed as child of element figure in this context". However, <figure> is a block level element and a parent of a child <a href>, and should be allowed here. Why is it a validation error then?

Thanks!

1 个答案:

答案 0 :(得分:3)

<figure>

The spec says内容模型是:

  

要么:一个figcaption元素后跟流内容   或者:流内容后跟一个figcaption元素   或者:流量内容。

您有一个规则1和2的组合(一个figcaption位于之后,后面是流内容),这是不允许的。

换句话说,<figcaption>必须是<figure>中的第一个或最后一个元素。它不能在中间。