<div>
<img src="" />
<p>MY PARAGRAPH HERE<p>
</div>
This is a pet hate of mine and if you use the above structure you are in effect saying this:
Code:
<div>
I'm a
<p>badly structured section</p>
</div>
Note that the above code will validate but it is not semantically correct.
Neither is the following acceptable.
Code:
<div>
<span>I'm a</span>
<p>badly structured section</p>
</div>
In both the above cases you have inline elements running straight into block level elements and the browser has to step in and create an anonymous block box so that the structure is correct.
Any time you make the browser think then you are asking for trouble in IE and indeed the half finished structure causes many bugs that I see time and time again in the forums and results in missing or misplaced content.
Therefore I always try to ensure that all inline elements are on the same level as other inline elements and that they are contained within a block element before another block element starts.
I prefer to wrap images in paragraph elements because most of the time it makes sense to me and I hate wasting the four extra characters that a div takes. (I see divs as divisions of content rather than containers for individual items although I accept that at times there is no choice.)
If an image in the html then that means it's important content and saying something to the visitor. When you say something you use paragraphs.
Therefore to avoid bugs in IE and also to be semantically correct I would do this.
Code:
<div>
<p><img src="".... /></p>
<p>well structured section</p>
</div>
Although I agree that this is also acceptable but not my preferred method.
Code:
<div>
<div><img src="".... /></div>
<p>well structured section</p>
</div>
Bookmarks