Is it possible to wrap an You would just want to style the "a" tag as Eclipse is appropriately telling you that your HTML is not to spec (as a div tag is not allowed in an anchor tag). But, since you seem to want to be visually making the anchor look like a big-ol-box, then simply style it as such :) That structure would be valid in HTML5 since in HTML5 anchors can wrap almost any element except for other anchors and form controls. Most browsers nowadays have support for this and will parse the code in the question as valid HTML. The answer below was written in 2011, and may be useful if you're supporting legacy browsers (*cough* Internet Explorer *cough*). Older browsers without HTML5 parsers (like, say, Firefox 3.6) will still get confused over that, and possibly mess up the DOM structure. Three options for HTML4 - use all inline elements: Then style with Use JavaScript and And (assuming jQuery) And Or lastly use absolute positioning to place an And CSS: This won't work with older versions of IE, of course. HTML provides two general elements, where Now, while both can be made by css However, css is only meant to be for making what an element looks like (presentation), but not actually be like (functionality), so it doesn't change an element's basic nature, though that gets very fuzzy in practice. A So, to mitigate against possible conflicts between their natural and css-induced behaviours, it is better to allow: This will also mitigate against tending to build page structures that will likely end up churning out error and warning messages. Basically, NEVER embed a natural block tag inside a natural inline tag, at any depth. Why there is a really a distinction is perhaps due to a simplistic idea of what HTML was going to be used for when it was first dreamed up. Certainly, framework makers got around a lot of these what-to-embed-where problems by just using myriads of It meant that they really only had to manage one tag per purpose and manage it as if it was an isolated environment. So what was meant to be an occasionally-used functional grouping tag became the web's Lego block. And none of them are going to risk breaking their frameworks by converting to HTML5 semantic tags in a hurry. Another simple solution - just add an onclick event handler to the div thusly: This works great for me but there is one small gotcha. I'm not sure how search engine friendly this is. I fear that google's web crawlers might not find this link so I also tend to include a traditional A HREF link somewhere in the block like this: One easy way to make the div a link/clickable is by using html javascript onclick attribute: While the When I encountered the problem i swapped the div tag with a Here's an example: tag around
display: block;
<a href=etc etc>
<span class="layout">
<span class="title">
Video Type
<span class="description">Video description</span>
</span>
</span>
</a>
display: block
:hover
: <div class="layout">
<div class="title">
Video Type
<div class="description">Video description</div>
</div>
</div>
$('.layout').click(function(){
// Do something
}):
.layout:hover {
// Hover effect
}
a
anchor with CSS to cover the whole of .layout
<div class="layout">
<div class="title">
Video Type
<div class="description">Video description</div>
</div>
<a class="more_link" href="somewhere">More information</a>
</div>
.layout {
position: relative;
}
.layout .more_link {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-indent: -9999px;
z-index: 1000;
}
div
is a natural block element, and span
is a natural inline element. All other elements are similarly assigned to be a natural block or inline.display
to be any of inline
, inline-block
or block
, they are still treated for enclosure purposes as their natural selves, hence the warning messages. Leopards and spots sort of thing.span
made block
becomes a bully that kicks everything else off the line, which is very un-inline
sort of behaviour.
div
or any natural block tag to only ever be block
or inline-block
.span
or any natural inline tag to only ever be inline
or inline-block
.div
s everywhere, and 'divitis' was born, and still alive and well in every framework. Just have to press F12
in a browser on almost any commercial web page and drill down through a dozen div
s. This very page has 15 unbroken levels of div
s.<div class="layout" onclick="location.href='somewhere'">
<div class="title">
Video Type
<div class="description">Video description</div>
</div>
</div>
<div class="layout" onclick="location.href='destination_url'">
<div class="title">
Video Type
<div class="description">Video description</div>
</div>
<a href="destination_url">This is a link</a>
</div>
<div class="clickable-div" onclick="location.href='#';"><div> ... </div></div>
<a>
tag is not allowed to contain <div>
element, it is allowed to contain other inline elements such as <span>
.<span>
. Since the span tag is an inline element, you need to apply a display:block
to the css of your <span>
element, in order to make it behave like the <div>
block element.
This should be valid xhtml and does not require any javascript.<a href="#">
<span style="display:block">
Some content. Maybe some other span elements, or images.
</span>
</a>