Javascript - 表头中心对齐

时间:2014-02-21 12:21:28

标签: javascript html dom

我正在创建一个表格如下

table = document.createElement('table');
table.style.textAlign = 'center';
table.setAttribute('border', '2');

var thead = document.createElement('thead');
thead.style.color = "fuchsia ";
thead.style.textAlign = 'center';

当我填充表格时,行内容按预期居中对齐,但标题行始终保持对齐。我该怎么做才能使它居中对齐?

由于

1 个答案:

答案 0 :(得分:1)

theadth的容器。 th始终需要填充thead,因此标题行中心对齐的自然位置在th之内,所以......

var th = document.createElement('th');
th.style.color = "fuchsia ";
th.style.textAlign = 'center';

哦,而且,你的thead没有设置中心对齐,你在桌子上设置了两次。

相关问题