tags:

views:

22

answers:

1

According to the W3C wrapping multiple elements in 1 anchor tag is invalid.

I was wondering is there is a neat CSS solution for combining multiple heading and image tags into 1 valid clickable anchor?

I'm building a property listing site, and I want my 'mini listing boxes' to only have 1 anchor. Here's my invalid code:

<a href="listings.html">
  <h4>FOR SALE</h4>
  <h2>Listing Title</h2>
  <h4>$1,000,000</h4>
</a>
A: 

Actually no, it's not invalid, as long as it's inline elements (spans, images...).

And in HTML5 it's also valid to use block elements (divs, or, like your examples, headings). Firefox doesn't like this too much, though, sometimes.

So, if you want to stick to old HTML 4/XHTML 1 you need to turn those headings into spans (and style them accordingly), while if you use HTML5 and Firefox behaves, your code is formally okay (note: it doesn't make much sense to use headings like that, anyway).

Laz75
Why does it not make sense to use headings in this way? Surely I get more SEO value using headings rather than spans?
trnsfrmr
You should use headings for headings, that is when there is a part of your page that needs a title. An actual title, you shouldn't mark up all of your text with headings for SEO reasons. Also, search engines are not easily fooled by tricks like this. Good, well-marked-up content will always win, in search engines too.In this example the only heading that could make sense is the h2.
Laz75
Ah, I see what you mean now. I'll ditch the H4s. Thanks for the advice, Laz75!
trnsfrmr