Forum Moderators: not2easy

Message Too Old, No Replies

Centering tables via CSS margins auto

         

Rad1

8:00 pm on Mar 9, 2009 (gmt 0)

10+ Year Member



Hi.

Can somebody tell me why (when centering tables), this:

table.center {
margin-left, margin-right: auto;
}

does not work, but this does:

table.center {
margin-left:auto;
margin-right:auto;
}

They should be the same, no?

TIA.

CSS_Kidd

8:32 pm on Mar 9, 2009 (gmt 0)

10+ Year Member



The First one:

table.center {
margin-left, margin-right: auto;
}

Change the , to a ; after margin-left

lavazza

8:37 pm on Mar 9, 2009 (gmt 0)

10+ Year Member



No

Selectors can be separated by commas

  • table AND table.myClassName are examples of selectors

    Properties and their values are separated by semicolons

  • margin-left AND margin-right are examples of properties
  • auto AND 3em and 10px are examples of values
  • swa66

    8:41 pm on Mar 9, 2009 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Depending on what top and bottom margins you need (I'll assume none in this example), there is a shorthand notation for margins:
    margin: 0 auto;
    (sets top and bottom margins to 0 and left and right to auto)

    More info: [w3.org...]

    Rad1

    8:45 pm on Mar 9, 2009 (gmt 0)

    10+ Year Member



    oh yeah,

    i was thinking of separating SELECTORS by a comma.

    didn't realize that was a property.

    noob mistake.

    thanks.

    i knew there was a simple explanation.