Forum Moderators: not2easy

Message Too Old, No Replies

Empty <div>?

...is it alright?

         

Emperor

6:25 am on Jan 29, 2005 (gmt 0)

10+ Year Member



Hi guys,

Is it alright to use an empty <div>?

Like so:

<div class="item">some item</div>
<div class="item">some item</div>
<div style="margin-bottom: 1.0em;"></div>
<div class="item">some item</div>
<div class="item">some item</div>

Notice the empty one in the middle. It works fine in Firefox and IE6 but maybe I should be doing something else?

Take care,
Emperor

BonRouge

1:10 pm on Jan 29, 2005 (gmt 0)

10+ Year Member



It is valid, but you'd be better giving the div above it an id and putting the bottom margin in that.

createErrorMsg

3:41 pm on Jan 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I agree with BonRouge. If the <div>s purpose is to make an empty space on the page, you're slipping into the tables-based mindset of using html mark-up to control presentation. Better to style an existing, semantic element in a way that provides the appearance you want.

If, on the other hand, the purpose of the empty <div> is to hold content on some pages, but not on others, or even to serve as a potential place to hook styles onto at a later date, there's nothing wrong with adding it in.

If you haven't already, try taking a look at the html source code used on Dave Shea's CSS Zen Garden [csszengarden.com]. There's a lot of markup provided on that page for the sole purpose of giving designers a "hook" for their style info. Clearly the extra markup doesn't prevent the page from functioning, but, of course, it's used for a very specific purpose that is unique to that site's goals.

cEM

Webwork

4:39 pm on Jan 29, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What about an empty div, created and sized at design time, to reserve space for future content - say something fed into the space via SSI, such as an RSS feed, ads that haven't been sold yet but for which you wish to reserve space, AdSense, etc.

That would be a valid use of an empty div, unless I'm misguided which isn't unheard of.

4css

5:30 pm on Jan 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Webwork, I believe that CEM has answered this one for you,

"If, on the other hand, the purpose of the empty <div> is to hold content on some pages, but not on others, or even to serve as a potential place to hook styles onto at a later date, there's nothing wrong with adding it in."

So adding divs to hold future content is ok. And if you are in a planing stage to start out with, you are most likely going to have divs that you might want to use for something, and change it later. They can be added and removed as content desires.

Isn't css grand! ;)