MPDF 和溢出问题:隐藏在嵌套 div 上

发布于 2024-12-15 13:49:21 字数 2019 浏览 3 评论 0原文

我试图让 MPDF 正确打印带有溢出的 div:隐藏。我已经仔细阅读了他们的文档并尝试了各种方法。运气不好。根据 mpdf,带有“overflow:hidden”的块元素必须具有“position:absolute”或“position:fixed”集。当您只打印一个 div 时,这很好。当我尝试嵌套 div 并需要内部 div 来剪辑文本时,就会出现问题。这就是我的意思:

这打印出来很好

$html = <<< EOM
<div style='width:300px;height:100px;position:absolute;overflow:hidden;border:1px solid black;'>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.  
</div>
$html = <<< EOM

这不是

$html = <<< EOM
<div style='border:1px solid red;position:relative;'>
<div style='width:300px;height:100px;position:absolute;overflow:hidden;border:1px solid black;'>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.  
</div>
</div>
$html = <<< EOM

php 脚本很简单

include("mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();

正如你所看到的,唯一的区别是一个 div 位于另一个 div 内。有谁知道如何做到这一点?

I am trying to get MPDF to correctly print divs with overflow:hidden. I've read their documentation up and down and tried various things. No luck. Per mpdf, block elements with overflow:hidden must have position:absolute or position:fixed set. That is fine when you printing just one div. The issue comes up when i try to nest divs and need the inner one to clip text. Here's what I mean:

This prints out fine

$html = <<< EOM
<div style='width:300px;height:100px;position:absolute;overflow:hidden;border:1px solid black;'>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.  
</div>
$html = <<< EOM

This does not

$html = <<< EOM
<div style='border:1px solid red;position:relative;'>
<div style='width:300px;height:100px;position:absolute;overflow:hidden;border:1px solid black;'>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.  
</div>
</div>
$html = <<< EOM

The php script is simple

include("mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();

As you can see the only difference is that one div is inside another one. Has anyone figured out how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遥远的她 2024-12-22 13:49:21

在 mpdf 中,您不能在嵌套 div 上使用 overflow:hidden;overflow:hidden; 只能在顶级元素上使用。

In mpdf you can't use overflow: hidden; on nested divs. overflow: hidden; can only be used on top level elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文