Getting an error in W3C Markup Validation when trying to get a whole <Figure> element as a link in a page

我只是一个虾纸丫 提交于 2019-12-31 03:08:05

问题


I am trying to get whole <figure> element as a link so i wrote these line of code :-

   <figure>
   <a href="#">
    <img src="images/product-image.jpg" alt="image  " />
    <span class="label"><span class="rotate">40%</span></span>
    <span class="curle-label_bg"></span>
    <figcaption><span class="product-brand">Brand of product</span>
    Main Caption here 
   <span class="save-money">Save 395.05</span>
   <span class="product-price">€169.30</span>
   </figcaption>
   </a>
   </figure>

I am getting an error "Element figcaption not allowed as child of element a in this context. (Suppressing further errors from this subtree.)" in http://validator.w3.org/ ,I have changed my Document Type in to HTML5 (experimental) in "More option", Can anybody tell me why i am getting this error or where i am going wrong?


回答1:


From the spec:

Contexts in which this element can be used: As the first or last child of a figure element.

You are trying to use it as a child element of an <a> not a <figure>




回答2:


Better to do this:

   <a href="#">
     <figure>
        <img src="images/product-image.jpg" alt="image  " />
        <span class="label"><span class="rotate">40%</span></span>
        <span class="curle-label_bg"></span>
        <figcaption><span class="product-brand">Brand of product</span>
          Main Caption here 
         <span class="save-money">Save 395.05</span>
         <span class="product-price">€169.30</span>
       </figcaption>
     </figure>
   </a>

Now the figure is enclosed within the a tag, and the figcaption is a child of the figure, not the <a>



来源:https://stackoverflow.com/questions/7633350/getting-an-error-in-w3c-markup-validation-when-trying-to-get-a-whole-figure-el

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