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!
答案 0 :(得分:3)
<figure>
的The spec says内容模型是:
要么:一个
figcaption
元素后跟流内容 或者:流内容后跟一个figcaption
元素 或者:流量内容。
您有一个规则1和2的组合(一个figcaption
位于和之后,后面是流内容),这是不允许的。
换句话说,<figcaption>
必须是<figure>
中的第一个或最后一个元素。它不能在中间。