2014-09-28 49 views
1

下面的代碼適用於我所需要的(三個水平按鈕),除非它不居中。它位於屏幕的左側。我做了一些研究,無法修復它,並嘗試使用「float」和「display:inline」的無表設計,但無法使其居中。請幫助!如何將表格放在表格中間?

<table> 
<td> 
<tr> 
<form method="get" action="index.php"><button type="submit">Home</button></form> 
<form method="get" action="signup"><button type="submit">Create Account</button></form> 
<form method="get" action="login"><button type="submit">Login to Account</button></form> 
</tr> 
</td> 
</table> 
+0

你真的不應該用表格來這... – Bart 2014-09-28 19:07:53

回答

0

正如其他人提到的<td>應該在<tr>之內。默認情況下,<form>顯示爲塊元素。將其更改爲inline-block

table { 
 
    border: 1px solid red; 
 
    width: 100%; 
 
} 
 
td { 
 
    border: 1px solid green; 
 
    text-align: center; 
 
} 
 
form { 
 
    display: inline-block; 
 
}
<table> 
 
    <tr> 
 
    <td> 
 
     <form method="get" action="index.php"> 
 
     <button type="submit">Home</button> 
 
     </form> 
 
     <form method="get" action="signup"> 
 
     <button type="submit">Create Account</button> 
 
     </form> 
 
     <form method="get" action="login"> 
 
     <button type="submit">Login to Account</button> 
 
     </form> 
 
    </td> 
 
    </tr> 
 
</table>

+0

完美,謝謝! – zoldos 2014-09-29 01:21:42

0

<tr>的(行)應該是在外面

<table> 
    <tr> 
     <td> 
      <form method="get" action="index.php"><button type="submit">Home</button></form> 
     </td> 
     <td> 
      <form method="get" action="signup"><button type="submit">Create Account</button></form> 
     </td> 
     <td> 
      <form method="get" action="login"><button type="submit">Login to Account</button></form> 
     </td> 
    </tr> 
</table> 

jsFiddle Demo

0

逆HTML中的trtd

<table> 
<tr> 
<td> 
<form method="get" action="index.php"><button type="submit">Home</button></form> 
</td> 
<td> 
<form method="get" action="signup"><button type="submit">Create Account</button></form> 
</td> 
<td> 
<form method="get" action="login"><button type="submit">Login to Account</button></form> 
</td> 
</tr> 
</table> 

,然後嘗試在這CSS

td { 
    text-align: center; 
} 

而且不要忘記設置你的表格的寬度! (所有窗口100%)