简体   繁体   中英

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

I'm generating an HTML table from an array of objects. 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.

Example

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM