Forum Moderators: not2easy
<a href="index.html"><div id="banner"></div></a>
This works very well but it's not HTML 4.01 compliant using a transitional DTD. The problem is that a block level element cannot be nested inside an <a> tag.
I do not want to use an <img> tag for the banner, because I want to keep the site design completely separate from the content. However, I have no idea how to change this so that it is HTML 4.01 compliant. Any suggestions?
HTML:
<a href="index.html"><span id="banner"></span></a>
CSS:
#banner
{
display: block;
...
}
Thanks a lot guys.
I changed the <div> to <span> and in my style sheet I simply specified that the banner selector should be a block level element to maintain the layout
Technically, you've still nested a block-level element in an inline <a>nchor. Your code will pass through the Validator without throwing an error because the html validator doesn't dip into your CSS to see how you've altered the display setting. it uses the default setting for each element to determine the legality of your nesting.
However, when the browser renders the page, it will render the <a> as inline and the <span> as block, as per your CSS, and should this illegal nesting cause any rendering problems, you would experience them.
I think Storyman has given you a far better suggestion. By using an image replacement technique, you not only create valid code, but you also provide a text-only version of your header for those viewing your page without the benefit of styles or those hearing it through a screen reader.
Start with your original div. Nest a header tag in it, and in that an anchor containing a text version of whatever the image-header says. Then style the anchor per the code below...
html:
<div id="header">
<h1><a href="#">MySite</a></h1>
</div>css:
#header{
height:150px; /*or whatever*/
width:700px;
}
h1{
height:150px; /*match to #header height*/
text-indent: -100.0em;
overflow: hidden;
background: url(path/to/image.gif);
}
h1 a{
display:block;
line-height:150px; /*match to h1 height*/
}
cEM