SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru mdumka's Avatar
    Join Date
    Jul 2003
    Location
    True North
    Posts
    642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is the difference in these 2 samples of code?

    Hello Could Some one tell me the difference bewtween these 2 sections of code for an table:

    Code:
    <TABLE width="100%" align=center border=1>
    <TBODY>
    	<TR>
    		<TD>&nbsp;</TD>
    	</TR>
    </TBODY>
    </TABLE>
    Then ...

    Code:
    <TABLE width="100%" align="center" border="1">
    	<TR>
    		<TD>&nbsp;</TD>
    	</TR>
    </TABLE>
    Thanks

  2. #2
    SitePoint Wizard bronze trophy conradical's Avatar
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    2,355
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    hmm, glad you brought that up! I've used both and would like to know the difference!

  3. #3
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no difference in terms of the DOM. The TBODY element is there in both cases because the element is required in HTML4 (although both tags are optional). The following example is also exactly the same (with exception to text nodes of white space between the elements...):
    Code:
    <table width="100%" align="center" border="1">
     <tr>
      <td>&#160;
    </table>
    Simon Pieters

  4. #4
    SitePoint Guru mdumka's Avatar
    Join Date
    Jul 2003
    Location
    True North
    Posts
    642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but what about the missing quotes arround attribute values?

  5. #5
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.w3.org/TR/html4/intro/sgm...tml#attributes

    It's identical in the DOM.

    Also, you could use attribute minimization:
    Code:
    <table center>
    That is the same as
    Code:
    <table align="center">
    ...although browsers generally only support attribute minimization for boolean attributes (disabled, readonly, selected, etc.).
    Simon Pieters

  6. #6
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    none of the examples except the one with quotes around all attributes is correct, attribute values should ALWAYS be surrounded by either a ' or a " ... and as you move into xhtml and newer languages they are absolutely mandatory so get into the habit now!

    although browsers generally only support attribute minimization for boolean attributes (disabled, readonly, selected, etc.).
    This is something else that is no longer accepted in xhtml .... boolean attribute should be done like this:

    readonly='readonly'

    ANd I might also point out in xhtml ALL html tags MUST be in lowercase!

    In my eyes it just poor coding to NOT do this, if you wanted to work for me and showed me that code I would say not thanks! It only takes a second to do it and it shows you are looking forward to the newer versions of the language!

  7. #7
    SitePoint Guru mdumka's Avatar
    Join Date
    Jul 2003
    Location
    True North
    Posts
    642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dalton,

    The reason I ask this is because I am using a CMS Template designer (Has to be used to interact with the custom backend) and it changes:

    Code:
    <TABLE width="100%" align="center" border="1">
    	<TR>
    		<TD>&nbsp;</TD>
    	</TR>
    </TABLE>
    To...

    Code:
    <TABLE width="100%" align=center border=1>
    <TBODY>
    	<TR>
    		<TD>&nbsp;</TD>
    	</TR>
    </TBODY>
    </TABLE>
    I think because of this generator:

    Code:
    <META content="MSHTML 6.00.2800.1505" name=GENERATOR>
    Thanks

  8. #8
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought we were discussing HTML4 here, not XHTML. The examples here are all syntactically valid, and semantically identical, although I wouldn't say that is conformant because a single non-breaking space inside a table doesn't actually mean anything (or does it? )...

    MSHTML probably includes the TBODY tags because the TBODY element is present in the DOM (just like it would include the HEAD and BODY tags for instance).
    Simon Pieters

  9. #9
    SitePoint Guru mdumka's Avatar
    Join Date
    Jul 2003
    Location
    True North
    Posts
    642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    zcorpan,

    I do not know XHTML but I haver seen attribute values not surrounded in quotes.

    Is this method new or old.

  10. #10
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A table in HTML always contains at least one TBODY, whether or not it's explicitly specified. A table may also contain a THEAD and/or a TFOOT, both of which must occur before the first TBODY.

    These element types were introduced in HTML 4, so they belong to the most modern flavour of HTML.

    A TBODY defines a row group, just as a COLGROUP element defines a column group. It can be useful for CSS styling (please note that you need to have an explicit <tbody> in XHTML to use it in a CSS rule). It's also useful for defining the scope of header cells (TH), as in
    HTML Code:
    <th scope="rowgroup">Header</th>
    Quoting attribute values is a very good habit. Although HTML (but not XHTML) allows certain values to be unquoted, I think it's quite unnecessary to try to remember the rules instead of always using quotes.
    Birnam wood is come to Dunsinane


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
  •