表格单元格中的文本不在标题中居中

时间:2013-08-01 01:52:08

标签: html css

CSS:

.one {
    width: 13%;
}

.two {
    width: 30%;
}

.three {
    width: 30%;
}

HTML:

<table>
    <tr>
        <th class= "one">Quantity</th>
        <th class= "two">Info</th>
        <th class= "three">Price</th>
    </tr>
    <tr>
        <td class = "one"><input type="text" name="quantity1" value=""/>
        <td class = "two">Cheap Monday Jeans 30/34 </td>
        <td class = "three">$39.99 </td>
    </tr>
    <tr>
        <td class = "one"><input type="text" name="quantity2" value=""/></td>
        <td class = "two">Herschel Bag (free) </td>
        <td class = "three">$129.99 </td>
    </tr>
    <tr>
        <td class = "one"><input type="text" name="quantity3" value=""/></td>
        <td class = "two">Diesel t-shirt (s) </td>
        <td class = "three">$59.99 </td>
    </tr>
    <tr>
        <td class = "one"><input type="text" name="quantity4" value=""/></td>
        <td class = "two">Superdry Patrol Lite Jacket (m) </td>
        <td class = "three">$129.99 </td>
    </tr>
    <tr>
        <td class = "one"><input type="text" name="quantity5" value=""/></td>
        <td class = "two">I love Canada t-shirt (s) </td>
        <td class = "three">$19.99 </td>
    </tr>
</table>

我希望表格行(衣服信息和价格)在表格标题的正下方对齐。我不知道为什么表行向左倾斜,并且不能在标题下方对齐。

enter image description here

2 个答案:

答案 0 :(得分:2)

首先,你忘了在第一次输入后关闭td。

 <td class = "one"><input type="text" name="quantity1" value=""/></td>

您可以添加此css以使其居中

td
{
    text-align:center;    
}

查看 EXAMPLE

答案 1 :(得分:0)

您可以将此添加到您的css:

td.two, td.three {
  text-align:right;
}

您需要td前缀,因为th使用相同的css类。

我希望有所帮助。