I am working on a web applicaton. And what we also create is something that could be described as inline editing. Just to portray thing I am trying to solve I use example of Facebook post.
You have post like.
Steve Jobs added 5 new photos
Steve Jobs is link that redirects to his profile so in HTML, that would be:
<div class="post-block">
<p><a href="stevejobs/" title="#">Steve Jobs</a> added 5 new photos.<p>
</div>
But what I want is the whole post "block" to be clickable although I want only that name to appear to be link. Normally in HTML logic would say to to this:
<a href="stevejobs/" title="#"><div class="post-block">
<p><a href="stevejobs/" title="#">Steve Jobs</a> added 5 new photos.<p>
</div></a>
But this isn't semantically correct. Quick look to HTML 4.01 or any other standard says something like this:
Links and anchors defined by the A element must not be nested; an A element must not contain any other A elements.
How to create it semantically correct other than using javascript and defining div:hover state for the whole "div anchor"?
HTML:
CSS:
Just replace the anchor tag around "Steve Jobs" in your second example with a span and style it as you want:
with CSS:
or whatever styles you're looking to apply or not apply. Actually I would try to lose the div and put the class on the anchor tag, unless there's other reasons for keeping that structure.
I have had the same issue for years, in that I want to maintain HTML semantics and SEO semantics too e.g. heading tags and paragraphs etc., while still keeping default anchor behaviours, e.g. indicating the destination URL in-browser, keeping tabbing intact and keeping the default anchor hover actions, which JavaScript doesn't do inherently.
The best solution I could figure was to put an absolutely positioned, block-level anchor over (covering) the content, and use the parent element's hover action to integrate any behaviours into the actual content, which is semantically correct and should be parsed correctly by all web-crawlers, thus:
This works well for block and grid layouts and even plays nice with touch devices, because the anchor itself has no hover action - which some devices hijack the first click for :)
Not 100% sure if search engines penalise the text indent, but there are any number of additional work-arounds, discussion here to get anyone interested started.
Nesting anchor tag is forbidden.
If you want only the name to appear as a link use anchor tag. And if you need entire block to be clickable do it in onclick function in jquery. Something like
In HTML5,
a
can be used as block-level element.Now, remove the default link styling with CSS (
.post-block a {text-decoration:none;}
).To get a link style back for the name, enclose the name in an element and add a class like "name". The
b
element would be a suitable choice here (otherwise usespan
):Now to get back the styling:
.post-block .name {text-decoration:underline;}
.Enclosing the name in an element even allows you to use the microformat hCard, if you like.
Since you don't want javascript(which would have been easier), here is another method:
Any other style effects can be added. Such as
cursor: none;
etc. depending on your desired effect.