Web Standards Design

 

Correct divs

Page history last edited by Joseph Lowery 1 yr ago

Using divs wisely

The <div> tag referenced here contains a single element and there's a better way to handle this type of code. Rather than surround your paragraph, image or other element with a <div> tag, why not apply an ID or class to the element itself?

 

Here's an example of the alternative method suggested. Let's say you've got an image within a <div> tag which has a class of "headshot", like this:

<div class="headshot">

<img src="zeldman.jpg" />

</div>

 

A neater (literally) approach would be to apply the class directly to the <img> tag:

<img src="zeldman.jpg" class="headshot" />

 

Taking this route reduces excess code and keeps everything nice and tidy.

 

Comments (0)

You don't have permission to comment on this page.