[英]I'm having trouble centering a cell of an HTML table
I'm generating an HTML table from an array of objects.我正在从对象数组生成一个 HTML 表。 If the signature is on the left, I need to put it in the middle.
如果签名在左边,我需要把它放在中间。 In case I have two signatures, I need to leave them centralized, as they already are.
如果我有两个签名,我需要让它们保持集中,因为它们已经是。
My current code:我当前的代码:
var result = [
{name: "John",
jobPosition: "President"
},
{name: "Marc",
jobPosition: "Director"
},
{name: "Paul",
jobPosition: "Director"
},
{name: "Mary",
jobPosition: "Director"
},
{name: "Carl",
jobPosition: "Geral Secretary"
},
];
var table = '<table style=" height: 94px;" border="0" width="100%" cellspacing="0" cellpadding="0"><tbody>';
result.forEach(function(item, index) {
if (index % 2 == 0) {
table += '<tr style="height: 35px;">';
}
table += '<td style="width: 50%; height: 150px; text-align: center; font-family: arial; font-size: 12pt;" valign="top"><p>_____________________________</p><p>' + item.name + '</p><p>' + item.jobPosition + '</p></td>';
if (index % 2 == 1 || index == (result.length - 1)) {
table += '</tr>';
}
});
table += '</tbody></table>';
gs.info(table);
In this example,Carl's signature needs to come in the middle.在这个例子中,Carl 的签名需要出现在中间。
Thanks in advance.提前致谢。
excuse me sir.对不起,先生。 now i found out your desire.
现在我发现了你的愿望。
you should add colspan attribute to te last td if index % 2 == 1 and set the amount of this colspan to 2如果 index % 2 == 1 则应将 colspan 属性添加到 te last td 并将此 colspan 的数量设置为 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.