Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Valid XHTML Clickable Block Region

Tags:

css

xhtml

seo

I'm trying to make a "clickable" region.

<a
  style="display: block"
  href="http://stackoverflow.com">
  StackOverflow
</a>

A is an inline element but the CSS made it a block.

If the above is valid, then the following should be valid too:

<a
  style="display: block"
  href="http://stackoverflow.com">
  <div>Some DIV that links to StackOverflow</div>
</a>

But validator.w3.org shouldn't be flagging it as invalid (which it is right now).

If it is invalid, what would be the most proper way to make a block element "clickable" and redirects to an arbitrary page. I'm aware I can use JS onclick to achieve this behaviour, but how will Google see this?

like image 618
Adrian Godong Avatar asked Dec 08 '22 07:12

Adrian Godong


1 Answers

The validator is correct - you can't put <div> inside <a>, no matter what you do afterwards with CSS.

The proper thing to do is what you did in your first code block - <a style="display: block;">

If you want something inside that you can do <a style="display: block;"><span style="display: block;">

like image 177
Greg Avatar answered Dec 31 '22 20:12

Greg