
Originally Posted by
deathshadow60
But as Paul began to imply, it's an old argument. Me? I err on the side of "don't add an extra element to the DOM for NOTHING".
Yes it's an old argument and it's a pet hate of mine (you have to have some don't you
) so I may be biased a little.
Usually I wouldn't add an extra element where none is necessary but in this case the browser will automatically construct an anonymous block box for you - so why not save the browser the trouble
.
When you do this:
Code:
<p>This is some text</p>
<img src="img.gif" alt="This is some text about the image" />
</div>
You are effectively doing this:
Code:
<div>
<p>This is some text</p>
This is some Text
</div>
And while it's not invalid - it's not semantically correct (IMO) and I occasionally see layouts breaking in Ie7 and under because of it. The white space after the image seems to make IE lose track of where the next element is exactly and elements become misplaced. Of course setting the image to display:block will usually cure the white space problems - but not always.
Agreed it's probably not enough to worry about as it happens pretty rarely but I do see about once every couple of months a problem where this has resulted in a broken layout.
Of course I occasionally break my own rules and in drop downs I don't add the extra elements and let the browser do it.
Code:
<ul id="nav">
<li><a href="#">Home</a></li>
<li><a href="#">About</a>
<ul>
<li><a href="#">History</a></li>
<li><a href="#">Team</a></li>
<li><a href="#">Offices</a></li>
</ul>
</li>
</ul>
So I do break the rules when it suits me 
The difference here is that the ul is absolutely placed and removed from the flow and the bug I mentioned is avoided.
It's a minor issue and most times you can ensure that the image is actually inside the element that it refers to anyway.
Code:
<p>This is a photo I took last week <img src="img.gif" alt="A Nice Sunset" /></p>
It's one of those times when I think that html got it wrong and images should have been block level elements by default and we wouldn't need to worry.
Bookmarks