簡體   English   中英

我無法將 HTML 表的單元格居中

[英]I'm having trouble centering a cell of an HTML table

我正在從對象數組生成一個 HTML 表。 如果簽名在左邊,我需要把它放在中間。 如果我有兩個簽名,我需要讓它們保持集中,因為它們已經是。

我當前的代碼:

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);

在這個例子中,Carl 的簽名需要出現在中間。

例子

提前致謝。

對不起,先生。 現在我發現了你的願望。

如果 index % 2 == 1 則應將 colspan 屬性添加到 te last td 並將此 colspan 的數量設置為 2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM