How to center a element

如何置中對齊

table {
text-align: center;
}

<table width="743" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../online-store/emall-graph/eamll-bg/emall-bg_r2_c2.jpg" width="743" height="119" /></td>
</tr>
</table>

W3C, Dreamweaver, CSS規格, 置中對齊

It doesn't work because text-align only affects text and in-line elements, but tables are block-level elements. You may go to the W3C see the definition

10.3 Computing widths and margins

The computed values of an element's 'width', 'margin-left', 'margin-right', 'left' and 'right' properties depend on the type of box generated and on each other. In principle, the computed values are the same as the specified values, with 'auto' replaced by some suitable value, but there are exceptions. The following situations need to be distinguished:

  1. inline, non-replaced elements
  2. inline, replaced elements
  3. block-level, non-replaced elements in normal flow
  4. block-level, replaced elements in normal flow
  5. floating, non-replaced elements
  6. floating, replaced elements
  7. absolutely positioned, non-replaced elements
  8. absolutely positioned, replaced elements

Points 1-6 include relative positioning

10.3.1 Inline, non-replaced elements

The 'width' property does not apply. A specified value of 'auto' for 'left', 'right', 'margin-left' or 'margin-right' becomes a computed value of '0'.

10.3.2 Inline, replaced elements

A specified value of 'auto' for 'left', 'right', 'margin-left' or 'margin-right' becomes a computed value of '0'. A specified value of 'auto' for 'width' gives the element's intrinsic width as the computed value.

看懂上面的遊戲規則 ? 滋味如何 ? 是不是比紙板還硬 ?

W3C 鼓吹CSS的神奇,但 設計人員看到W3C的網站或CSS規格, 保證讓人難以消化 Run for the life。W3C是由一群天才工程師組成,可能缺少美術創意, 不會廣告宣傳, 這也是CSS從1996就公佈, 卻末能推廣的理由之一

另外理由是W3C是網頁規格的 是高指導原則,不是最高指導杈威。

幸運的是 W3C部分文件已有人翻譯成中文: W3C中文翻譯


回到主題 如何置中對齊 請看 下一頁




press return home page