0

Here is my fiddle: http://jsfiddle.net/rkfC9/

It used to be so easy when you could simply write in the HTML itself and it should be even easier with CSS but nothing works for me. What is the EASIEST and simplest way to center the contents in both rows in this table?

#table {
    float:left;
}
#table td {
    margin-left:auto;
    margin-right:auto;
}
#brand {
    width:40px;
    height:40px;
    background:red;
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
oceanic815
  • 483
  • 2
  • 9
  • 20

3 Answers3

0

I'd ask why you are using a table, but I'm going to assume it's for tabular data, and not just for layout purposes.

Therefore, an easy answer to your dilemma:

#table {
    float:left;
}
#table td {
    /* setting margins here does nothing... 
       margins are outside of a block element, 
       and td's are table-cell elements, and have no margin 
       text-align: center should take care of any text
       you need to center align. */
    text-align:center;
}
#brand {
    width:40px;
    height:40px;
    background:red;
    /* since this is a block element, with a specified width, 
       you can use margin:0 auto to get it centered within its container. */  
    margin:0 auto;
}

Hope this helps!

Jason M. Batchelor
  • 2,951
  • 16
  • 25
0

If you apply the margin settings to the content, it will be centred:

#brand {
    margin-left:auto;
    margin-right:auto;
    width:40px;
    height:40px;
    background:red;
}
Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
0

try like below it will help you...

#table {
    float:left;
}
#table td {
    margin-left:auto;
    margin-right:auto;
    text-align:center; 
}
#brand {
    width:40px;
    height:40px;
    background:red;
    margin: auto;
}

DEMO : http://jsfiddle.net/rkfC9/3/

Pandian
  • 8,848
  • 2
  • 23
  • 33