如何对齐此复选框

时间:2011-06-28 01:13:07

标签: html css css-tables

我有一张表,完成列只是复选框。

<th>我有一个提示“include?”现在想为<th>中的复选框添加一些JS,可能还有一些“全/无”文本。

坏ascii艺术如下:

------------             ------------
| include? |             | include? |
|   []     |             |   [] all |
------------             ------------
|   []     |  or, maybe  |   []     |
------------             ------------
|   []     |             |   []     |
------------             ------------

在任何一种情况下,我应该使用style来核对该复选框?

4 个答案:

答案 0 :(得分:3)

最简单的是使用text-align:center;

http://jsfiddle.net/jasongennaro/rhUjP/1/

修改

刚刚看到了你的其他要求,即我需要将文本左对齐,但要将中心复选框

在这种情况下,请将input放入span

span{display:inline-block; text-align:center; width:100px;}

widthwidth的{​​{1}}匹配。

http://jsfiddle.net/jasongennaro/rhUjP/3/

答案 1 :(得分:2)

.checkbox {
    display: block;
    margin: auto;
}

或者您可以设置:

th {
    text-align: center;
}

如果您希望整个class居中,请指定要包含的id<th> <th>,例如:http://jsfiddle.net/minitech/pJxgc/

答案 2 :(得分:2)

试试这个jsFiddle

    <table>
        <tbody>
            <tr><th><input type="checkbox" class="checkbox" />&nbsp;&nbsp;&nbsp;&nbsp;Hello</th></tr>
            <tr><td>My Table Data!</td></tr>
        </tbody>

    </table>

th {     text-align:center; }

答案 3 :(得分:0)

你的意思是this fiddle吗?