1

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?

<a href="link.html"><div style="display:inline;background:etc;"></div></a>
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Francisc
  • 77,430
  • 63
  • 180
  • 276
  • 1
    You may want to take a look at this answer: http://stackoverflow.com/questions/1827965/is-putting-a-div-inside-a-anchor-ever-correct/1828032#1828032 – bafromca May 18 '11 at 19:25

2 Answers2

2

No, according to the W3C a div may not live inside an a element, unless you're declaring the doctype as 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?

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

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
2

No, block level elements aren't allowed inside inline level elements, and will cause undefined behaviour. Use a span instead.

Tatu Ulmanen
  • 123,288
  • 34
  • 187
  • 185