How to center html table?

前端 未结 5 2251
小鲜肉
小鲜肉 2020-12-19 23:08

Trying to create proper PDF document, using PHP and TCPDF.

Can you help me, how can I use writeHTML function to create and center table, in TCPDF?

Tryed wit

相关标签:
5条回答
  • 2020-12-19 23:25

    Never done anything like this however, this is the code you would need to center a table that is the cross browser compatible

    <div style="text:align:center;">
      <table style="margin:0px auto" border="1" width="200" align="center">
        <tr>
          <td><b>Invoice number: </b></td>
        </tr>
      </table>
      <br />
      <table style="margin:0px auto"border="1" width="200" align="center">
        <tr>
          <td>Client</td>
        </tr>
      </table>
      <br />
    </div>
    

    If pdfs support css i would advise styling the html elements using css

    table{
      border:1px solid black;
      margin:0px auto;
      text-align:center;
      width:200px;
    }
    

    Hope this helps!

    0 讨论(0)
  • 2020-12-19 23:26

    Try replacing your opening div tag with this...

    <div style="margin:5px auto; width:50%">
    
    0 讨论(0)
  • 2020-12-19 23:37

    Try this code; it worked for me:

    <table style="width:100%">
      <tr>
        <td style="width:30%">left margin</td>
        <td style="width:40%">
          <table border="1" style="width:100%">
            <thead>
              <tr>
                <td style="width:100%" colspan="2"></td>
              </tr>
              <tr>
                <td style="width:40%"><b></b></td>
                <td style="width:60%"><b></b></td>
              </tr>
            </thead>
          </table>
        </td>
        <td style="width:30%">rigth margin</td>
      </tr>
    </table>
    
    0 讨论(0)
  • 2020-12-19 23:40

    You have to make a table with 3 columns, set the width for every one of them and in the middle one you have to create your table.

    <table>
    <tr>
    <td style="width:25%"></td>
    <td style="width:50%"><table><tr><td>Your content</td></tr></table></td>
    <td style="width:25%"></td>
    </tr>
    </table>
    

    I'm not proud of this method but it's working :)

    0 讨论(0)
  • 2020-12-19 23:44

    Ok, so I don't know if there is solution for my problem...

    However, I did manage to solve it by using writeHTMLCell funcion, ie.

    $this->writeHTMLCell(50, 0, 50, 50, 'cellcontent', 'LRTB', 1, 0, true, 'L'); 
    

    If somebody can find better solution, please reply.

    Tnx!

    0 讨论(0)
提交回复
热议问题