2017-10-17 55 views
0

試圖複製這種設計/結構: 注意在桌子一側的兩個盒子和另一個大的盒子下面! enter image description here 我將如何實現這個使用表css?這裏是我當前的代碼,這是垂直堆疊:如何水平對齊css表格元素?

<body> 

<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable"> 
<tr> 
    <td align="center" valign="top"> 
     <table border="0" cellpadding="20" cellspacing="0" width="600" id="emailContainer"> 
      <tr> 
       <td align="center" valign="top"> 
        <table border="0" cellpadding="20" cellspacing="0" width="100%" id="emailHeader"> 
         <tr> 
          <td align="center" valign="top"> 
           This is where my body content goes. 
          </td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
      <tr> 
       <td align="center" valign="top"> 
        <table border="0" cellpadding="20" cellspacing="0" width="100%" id="emailBody"> 
         <tr> 
          <td align="center" valign="top"> 
           This is where my body content goes. 
          </td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
      <tr> 
       <td align="center" valign="top"> 
        <table border="0" cellpadding="20" cellspacing="0" width="100%" id="emailFooter"> 
         <tr> 
          <td align="center" valign="top"> 
           This is where my body content goes. 
          </td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
     </table> 
    </td> 
</tr> 
</table> 

</body> 

任何想法?:

+0

看到我的答案!我已經盡力了! – 2017-10-17 00:21:23

+0

研究使用柔性設計。它會用很少的代碼來完成你所需要的。 – jfeferman

+0

如果你認爲它好,你能接受我的答案嗎? – 2017-10-17 00:44:46

回答

1

史蒂芬是正確的,在theory

「正確」的方式使用CSS居中的表。如果左右邊距相等,則合適的瀏覽器應該將表格居中。要做到這一點最簡單的方法是將左,右頁邊距設置爲因此,人們可以在樣式表中寫上「自動」:

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

但這個答案的文章開頭提到給你所有其他方式集中一張桌子。

優雅的CSS跨瀏覽器的解決方案: 這個工作在兩個MSIE 6(怪癖和標準),Mozilla的,歌劇,甚至Netscape 4.x版本不設置任何明確的寬度:

div.centered 
{ 
    text-align: center; 
} 

    div.centered table 
{ 
    margin: 0 auto; 
    text-align: left; 
} 


    <div class="centered"> 
    <table> 
    … 
    </table> 
</div> 

看到這個post

編輯多數民衆贊成在中心這是水平只是改變neccecery css或看到here

+0

你爲什麼用大膽的文字向我們大喊大叫? – FluffyKitten

+0

我不是。對不起,刪除粗體,但它是使其脫穎而出 – 2017-10-17 00:50:34