简体   繁体   English

在 Laravel 中使用 DomPDF 调整表格单元格内的 div

[英]Adjusting the div inside a table cell using DomPDF in Laravel

I am adding a feature in my project wherein users can convert their data into pdf, but i am having a problem with css. How can i adjust this div so that it will align in the border of my table?我正在我的项目中添加一个功能,其中用户可以将他们的数据转换为 pdf,但我遇到了 css 的问题。我如何调整此 div 以便它与我的表格的边框对齐? padding and margin does not work since the table cell also adjusts.填充和边距不起作用,因为表格单元格也会调整。 or a im adding the wrong px?或者我添加了错误的像素? I displayed the table border so that you can see how far the border of the div is.我显示了表格边框,以便您可以看到 div 的边框有多远。 Here's the code这是代码

<table border="" style="border-collapse: collapse;font-size:12px;text-align: left;">  
<tr>
    <td colspan="2">
        <b>Email </b>
        <div  style="display: inline-block;border-bottom:.7px solid black;height:15px;padding:0px;width:200px;overflow:hidden;">  
                {!! $usermodel->email !!}
            </div>
    </td>
</tr>
</table>

电子邮件

If you want to align the div with the border of the table, you can add a vertical-align property to the td element with a value of top.如果想让div对齐表格的边框,可以给td元素添加一个vertical-align属性,值为top。 This will align the top of the div with the top of the table cell.这将使 div 的顶部与表格单元格的顶部对齐。

You can also try setting the height of the td element to the height of the div plus any additional padding you want to add.您还可以尝试将 td 元素的高度设置为 div 的高度加上您要添加的任何额外填充。 This will ensure that the entire div is contained within the table cell.这将确保整个 div 包含在表格单元格中。

    <table border="" style="border-collapse: collapse;font-size:12px;text-align: left;">  
  <tr>
    <td colspan="2" style="vertical-align: top; height: 30px;">
      <b>Email </b>
      <div  style="display: inline-block; border-bottom: .7px solid black; height: 15px; padding: 7.5px 0; width: 200px; overflow: hidden;">  
        {!! $usermodel->email !!}
      </div>
    </td>
  </tr>
</table>

Since you are using running styles, on this occasion, I suggest (perhaps could be bettered):-由于您正在使用运行 styles,在这种情况下,我建议(也许可以更好):-

 <table border="" style="border-collapse: collapse;font-size:12px;text-align: left;"> <tr> <td colspan="2"; style="font-size:18px; padding: 2px" > <b><sup>Email </sup></b> <div style="font-size:15px;padding: 2px 0px 2px; border-bottom: 1px solid black; display:inline-block; width: 220px; overflow: hidden;"> {.! $blackmamba@gmail.com !!} </div> </td> </tr> </table>

Try doing it in an external CSS stylesheet.尝试在外部 CSS 样式表中执行此操作。

看截图

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

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