Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite this code: clickable divs

Tags:

html

css

w3c

I'd like to change this:

<a href='foo'> 
    <div> Moo </div>
</a>

to be standards compliant (you're not supposed to have block elements in inline elements). Wiring javascript to the divs just for navigation seems like a hack and degrades accessibility.. In this case, my requirements are for 2 sets of borders on my fixed-dimension links, so the above non-compliant code works perfectly after applying styles.

Also, is "a { display:block; }" a legal way to circumvent the validation?

like image 514
Jimmy Avatar asked Dec 05 '25 06:12

Jimmy


1 Answers

Why not use a <span> rather than a <div> and set display:block on both elements?

Additionally, to answer your latter question: I don't believe adding display:block; to your anchor will make it pass validation. The validator checks to see if you're following (X)HTML rules, not how to present the page to the user.

like image 66
Zack The Human Avatar answered Dec 07 '25 22:12

Zack The Human



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!