简体   繁体   English

锚标记内的XHTML内联div

[英]XHTML inline div inside anchor tag

I want to have an image roll-over link and use sprites. 我想要一个图像翻转链接并使用精灵。 Is it ok to do put an inline div inside an anchor with no text? 将内联div放在没有文本的锚中是否可以?

<a href="link.html"><div style="display:inline;background:etc;"></div></a>

No, according to the W3C a div may not live inside an a element, unless you're declaring the doctype as HTML5*. 不,根据W3C一个div可以不住内部a元素,除非你声明的文档类型为HTML5 *。 Also, why would you use a div and make it display:inline if a span does the same and is standards-compliant at the same time? 另外,为什么要使用div并使其display:inline如果span相同且符合标准,则内联?

* http://davidwalsh.name/html5-elements-links * http://davidwalsh.name/html5-elements-links

No, block level elements aren't allowed inside inline level elements, and will cause undefined behaviour. 不,内联级别元素内不允许块级元素,并且会导致未定义的行为。 Use a span instead. 请改用span

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM