mPDF:文本与 p 对齐,table 中的 h1 - h6 不起作用

mPDF : text align with p , h1 - h6 in table not work

此代码不适用于 table 和 mPDF php class

    <table>
    <tr>
      <td class="contentDetails">
  <td class="contentDetails">
         <h3 style="text-align: right;"><strong>text align right</strong></h3>
         <h3 style="text-align: center;"><strong>text align center</strong></h3>
         <h3 style="text-align: left;"><strong>text align left</strong></h3>
     </td>
    </tr>
    </table>

我黑社会使用

.contentDetails > h3 {display: block;} 

但不起作用,在 td 之间它是来自编辑器 tinymcehtml

脚本中的完整代码 什么时候输出找到内容 td 文本左对齐而不是右对齐或居中

<?php

$html = '
<h1>mPDF</h1>
    <table style="border-collapse: collapse;
    font-size: 12px;
    font-weight: 700;
    margin-top: 5px; 
    border-top: 1px solid #777;
    width: 100%;">
<tbody>
<tr>
  <td class="contentDetails">
         <h3 style="text-align: right;"><strong>text align right</strong></h3>
         <h3 style="text-align: center;"><strong>text align center</strong></h3>
         <h3 style="text-align: left;"><strong>text align left</strong></h3>
     </td>
</tr>
</tbody>
</table>';

include("mpdf.php");

$mpdf=new mPDF('c'); 
$mpdf->WriteHTML($html);

$mpdf->Output();

exit;
?>

问题是容器的宽度与内容相符。将 table 宽度设置为 100%

table {
  width: 100%;
}
<table>
  <tr>
    <td class="contentDetails">
      <h3 style="text-align: right;"><strong>text align right</strong></h3>
      <h3 style="text-align: center;"><strong>text align center</strong></h3>
      <h3 style="text-align: left;"><strong>text align left</strong></h3>
    </td>
  </tr>
</table>

试试下面的代码。我想它会对你有所帮助。

<table width="100%">
  <tr>
    <td class="contentDetails">
     <th align="left"> <h3><strong>text align right</strong></h3></th>
     <th align="center"> <h3><strong>text align center</strong></h3></th>
     <th align="right"> <h3><strong>text align left</strong></h3></th>
    </td>
  </tr>
</table>

在此使用额外的标签。

我准备了很多小时的内容来打印(mPdf v.6)。现在我可以给大家一个建议。不要使用 tables 来对齐内容或简单地保留内容。元素的几乎所有 css 属性都可以正常工作。但是 - 但不能嵌套在 table 中。