Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Divs question

  1. #1
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Divs question

    is it common now if you have a div which is not going to contain anything to be done like this

    Code:
    <div id="" />
    instead of this

    Code:
    <div id=""> </div>

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Not if you want it to validate.

    If there is no CSS involved, then there is no need for empty id either. An empty div, while not exactly bad mark up will through a warning though. It is best to use as such:

    Code:
    <div>&nbsp;</div>
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    />

    is not any part of HTML.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    There is CSS but no text or content form the actual html side of things

  5. #5
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Well if you have CSS set up for an empty div, then you can use the class or ID still the same

    Code:
    <div id="empty">&nbsp;</div>
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There is nothing wrong with:

    HTML Code:
    <div></div>
    or with:

    HTML Code:
    <div id="whatever"></div>
    or with:

    HTML Code:
    <div class="whatever"></div>
    regardless of if 'whatever' is defined or not. If you want no class or id associated with the empty tag, use the first option. The only reason that you would need anything in there would be if you are going to use DOM level 2 javascript to replace it. Like:

    Code:
    documentGetElementById('whatever').firstChild.nodeValue='Hello World';
    For simple layout purposes though, an empty tag is fine, and may be styled however you like.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    There is nothing wrong with:
    technically.. no there isn't, except that with correct validating code it does produce a warning. empty elements such as <p> or <div> are not Strict INvalid, but the warning is there for a reason. Adding a space to the div does nothing to the layout and eliminates the warning
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This validates (W3c - verbose output):

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <div id="bull"></div>
    </body>
    </html>
    No warning. Excuse the id, I picked it before I read your post. Another thing, a space shouldn't be a layout problem (except perhaps in IE 6 - maybe even 7 - line height is often given even when there is only a space), but a nbsp entity will be unless the style is set to display:none;. An empty div with its clear property set can often be very advantageous in dealing with prior floats in a container with background, in which case its display property should not be none.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    My apologies.. I should have been more clear. HTML 4.01 Strict valid coding does NOT discern empty elements. It is the mark up validation WITH Tidy that will through the error ("Trimming empty <div>" )

    As stated, it isn't a problem, but some people care about such things, which is why I mentioned that adding the space will eliminate all of that.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    AFAIK, Tidy isn't a validator. It's a tool for cleaning up your code, right? Empty tags can often be left over from some content that got moved or removed. If that's the only reason for them being there, they should go. I imagine Tidy warns about them for that very reason, and that it is only a warning because there could be a valid reason (as mentioned in my previous post) for their being there.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •