SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    two tables - why side by side?

    Hello all,

    I did a search before posting but could not find an answer to my question below.

    I have two tables that I wish to have one on top of the other. Simple and should not be hard.

    HTML Code:
    <table>
    ...
    </table>
    
    <br />
    
    <table>
    ...
    </table>
    Now this works however when I add the align="left" attribute to the first table the second table aligns itself right next to the first table instead of staying down underneath the first name. So visually you have two tables right next to each other!

    HTML Code:
    <table align="left">
    ...
    </table>
    
    <br />
    
    <table>
    ...
    </table>
    Any ideas why this happens?

    Cheers

    Marc

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's no need to have a break between those tables.

    http://www.w3.org/TR/html4/struct/ta...ef-align-TABLE
    Using align="left" on a table moves the table is to the left of the document. Sort of like a float I suppose.
    "Never imagine yourself not to be otherwise than what
    it might appear to others that what you were or might
    have been was not otherwise than what you had been
    would have appeared to them to be otherwise."

  3. #3
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Eldacar's right. You need to remove the (depreciated) align="" attribute from the table to fix the issue.

  4. #4
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Thanks for the link to the spec. I suppose I am just wondering why the align attribute within the table tag controls another tables behaviour...

    What could I use instead of the align to say center a table within a web page? Div, span??

    Cheers

    Marc

  5. #5
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add an ID or class to your table, and then in your stylesheet, give that ID or class the following:
    Code:
    margin: 0 auto;
    And a width.

    Please note that align="" is valid in TD and TH elements though.

  6. #6
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your help Dan and eldacar!

  7. #7
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Just to add:

    The align isnt exactly controlling another table's behaviour, it is controlling the first table in the context of the whole page. What you are saying by using align=left is that you want the table to go to the left, and the content that follows to flow around it, much you would with an image for example. The 2nd table is the content that follows, so you would probably get the first table, then to the right the 2nd table maybe a bit lower down because of the line break (maybe not).

    Was the table not aligned to the left by default? Why did you need to set align="left" on it?

  8. #8
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider
    Just to add:

    The align isnt exactly controlling another table's behaviour, it is controlling the first table in the context of the whole page. What you are saying by using align=left is that you want the table to go to the left, and the content that follows to flow around it, much you would with an image for example. The 2nd table is the content that follows, so you would probably get the first table, then to the right the 2nd table maybe a bit lower down because of the line break (maybe not).

    Was the table not aligned to the left by default? Why did you need to set align="left" on it?
    Hello Stormrider,

    It was my lack of HTML knowledge which caused me to add the align="left" attribute in the table tag. I need to read more

    I thought that the align="left" would only be in the scope of the top table tag and all child elements underneath but it seems the attribute controls other high level objects as well - including the second table.

    Cheers

    Marc


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
  •