有效的HTML:'a'元素内的ul,p,div [英] Valid HTML: ul, p, div inside 'a' element
问题描述
我有一个div,如果您在div上的任意位置单击,它将打开另一个网页.因此,基本上整个div都是巨大的超链接.因此,我有一个 div ,然后在其中有一个 a 元素,然后在其中有了div的所有元素(所以有些 ul ,一些 p 等).
I have a div where if you click anywhere on the div it opens another webpage. So essentially the whole div is a giant hyperlink. Because of this, I have a div, then inside that I have an a element then inside that I have all the elements of the div(so some ul, some p etc.).
我的问题:当我尝试在w3标记验证器中验证HTML时,出现错误,因为我在 a 元素.
My Problem: When I try to validate my HTML in the w3 Markup validator, I get errors because I have an ul, p, etc. inside of an a element.
实际错误:
文档类型此处不允许元素"p";缺少其中之一对象",小程序",地图","iframe",按钮","ins","del"开始标签
document type does not allow element "p" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag
如何使我的HTML有效&仍然将我的div作为一个重要链接吗?
How can I make my HTML valid & still keep my div as one big link?
<div id="rentalAnnc">
<a class="sidebarLink" href="facilitiesForHire.html">
<p>KAZCARE has a range of Education Facilities available for Lease & Hire at its Bowral location.</p>
<!--<p>Click here for more information.</p>-->
</a>
</div>
推荐答案
您只能在HTML 5的锚点中包含块级内容.您不能在任何非草稿版本中使用.如果您希望它符合规范*,请切换到HTML 5.
You can only include block level content inside an anchor in HTML 5. You can't in any non-draft version. If you want it to conform* to a specification, switch to HTML 5.
请注意,这样做会引起问题.
*我们不要谈论< ins>
hack,因为DTD的表达能力不足以禁止它,但是规范的文字却可以使您以有效但不符合标准的方式进行操作是
* Let's not talk about the <ins>
hack which lets you do it in a valid but non-conformant way as DTDs aren't expressive enough to forbid it but the text of the spec is
这篇关于有效的HTML:'a'元素内的ul,p,div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!