SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: bah, center tag

  1. #1
    SitePoint Zealot Cheeser's Avatar
    Join Date
    Nov 2003
    Location
    Washington, DC
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    bah, center tag

    Ok, I want to center a table and be xhtml strict...

    I've tried using CSS:

    PHP Code:
    div
    {
        
    text-aligncenter;

    while this works in IE (not saying much there), it doesn't work in Opera, or any browsers using the Gecko engine (Fire[fox/bird], Netscape, Mozilla)

    my code is along the lines of:
    Code:
    <div>
        [table stuff]
    </div>


  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Code:
    div {
      text-align: center; /*for IE*/
    }
    div table {
      /*for other browsers*/
      text-align: left;
      margin: auto;
    }
    Try this code out. Make sure you have a defined width for your table though, either in the HTML or the CSS.

  3. #3
    SitePoint Zealot Cheeser's Avatar
    Join Date
    Nov 2003
    Location
    Washington, DC
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    Code:
    div {
      text-align: center; /*for IE*/
    }
    div table {
      /*for other browsers*/
      text-align: left;
      margin: auto;
    }
    im kinda a newbie to this... i dont want to copy code without understanding it, so what does the "div table" part do?

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    A margin value of "auto" tells the browser to take as much margin as possible. If "auto" is set on both the left and right margins, they will take up equal amounts of margin, effectively "centering" your element. As long as that element has a defined width, it will appear centered. The "text-align: left;" bit "resets" your text so it's not center-aligned. If you want centered text in your table on the other hand, feel free to remove that line.

    Hope this helps!

  5. #5
    SitePoint Zealot Cheeser's Avatar
    Join Date
    Nov 2003
    Location
    Washington, DC
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually, i understood that before, but how does "div table" differ from simply "div"

  6. #6
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    "div table" selects any tables that are inside of a <div>. Nothing more to it really.


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
  •