5

this code not work in table with mPDF php class enter image description here

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

i triad use

.contentDetails > h3 {display: block;} 

but not work and between td it's html from Editor tinymce

this full code from script and when do output found content the td text align left not right or center

<?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;
?>
GoldenFingers
  • 119
  • 1
  • 2
  • 10

3 Answers3

13

Try the below code. I think it will help you.

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

using extra tags in this.

Subin Thomas
  • 1,408
  • 10
  • 19
6

I have prepared a lot of hours a content to print (mPdf v.6). Now i can give an advice to all. Don't use tables to align content or simply hold the content. Almost all css properties of elements work fine. But - but must not be nested in table.

Jirka Kopřiva
  • 2,939
  • 25
  • 28
0

The problem is the width of the container which is fitting with the content. Set table width to 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>
m4n0
  • 29,823
  • 27
  • 76
  • 89