简体   繁体   English

如何对齐表格 td, tcpdf 中的图像

[英]How to align image in table td, tcpdf

I use tcpdf to generate pdf files.我使用 tcpdf 生成 pdf 个文件。

And there's a problem in aligning image in table td.表格 td 中的图像对齐存在问题。

I am uising $pdf->writeHTML($html, true, false, true, false, '');我正在使用$pdf->writeHTML($html, true, false, true, false, ''); in tcpdf.在 tcpdf 中。

在此处输入图像描述

html is clear from the image i have shared.从我分享的图片中可以清楚地看到 html。 html is just simple as html 很简单

<table>
  <tr>
    <td>&nbsp</td>
    <td>Picture</td>
    .......
  </tr>
  <tr>
    <td>1</td>
    <td style="text-align:center"><img src="abc.jpg" width="20" height="20" ></td>
    .......
  </tr>
</table>

Note: align="center", valign="middle", css margin and padding... nothing seems to work I tried on注意:align="center", valign="middle", css 边距和填充...我试过似乎没有任何效果

text-align:center push into center but not vertically. text-align:center 推入中心但不是垂直。

你检查了图像对齐吗?

<img align=center src="abc.jpg" width="20" height="20" >

Adding the following CSS to your td should work: 将以下CSS添加到您的td应该工作:

td {
    vertical-align: middle;
    text-align:center;
}

See a fiddle of it working. 看到它工作的小提琴

This will work.这会起作用。 As shown below, we can add a line break inside the <p> tag.如下所示,我们可以在<p>标签内添加一个换行符。

<table width="100%" style="border:1px solid #000;">
    <tr>
        <td style="text-align: center;">
            <p><br/>
                <img src="path/to/image" />
            </p>
        </td>
    </tr>
</table>

you can use : CSS: 你可以使用:CSS:

td img{
    margin:0 auto;
}

or use like @gayan 或者像@gayan一样使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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