Forum Moderators: mack
It seems to me div is good for laying out a site. Are there reasons why we shouldn't do this, or more appropriate alternatives?
David.
Are there reasons why we shouldn't do this, or more appropriate alternatives?
If your goal is presentation only, no.
If you want to create a "smart" document, one where the elements you use appropriately describe the content, then this is a very good reason not to use divs - except where appropriate. We want to do this so that machines and devices that cannot interpret context of anonymous text can get some clues from the markup. For most of us, this means search engine spiders, but other devices benefit from this as well.
<h1> is a page heading. <p> is a paragraph. <span> spans text. You see where it's going . . . a div is a generic container used to divide a page and it's purpose is to manipulate a layout. So if it's a container to divide up a page, it's a perfectly legitimate element because you don't want to assign a semantic meaning to these.
A common example, you have a navigation:
<div>Home</div>
<div>About</div>
<div>Contact</div>
But what is a navigation? A list of links:
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
It's important to remember you can style any element to imitate the behavior of any other element. You will often see div's "forced" to do a specific task when a paragraph or list will do just as well, and give semantic meaning to the content.
While we're on the topic, a pet peeve of mine,
blah blah blah blah <br><br>
blah blah <br><br>
blah<br><br>
Give your content meaning to machines parsing it.
<p>blah blah blah blah </p>
<p>blah blah </p>
<p>blah</p>
Does it make a difference in presentation? Not likely.