简体   繁体   English

使用 mPDF 在 div 中的 img 下不需要的空间

[英]Unwanted space under img in div using mPDF

I am using mPDF to create a PDF from the following HTML-Code:我正在使用 mPDF 从以下 HTML 代码创建 PDF:

<div style="border: 5px solid black; height: 115px;">
    <div style="width: 29%; height: 115px; float: left; background-color: red;">
        <img src="testimage.png"
             alt="Bild 1" style="height: 115px;">
    </div>
    <div style="width: 55%; float: left; padding-top: 60px; font-size: 18px; font-weight: bold;">
        SOME TEXT
    </div>
    <div style="float: right; width: 16%; font-size: 18px; padding-top: 10px;">
        <div style="float: left; width: 25px;">ANOTHER TEXT</div>
    </div>
</div>

The outcome in the PDF is rather unsatisfying: The outcome PDF 中的结果相当不令人满意:结果

I am dealing with this weird space below the image.我正在处理图像下方的这个奇怪的空间。 I tried giving the image a blue and the div a red background and it is always red, so the div is too high.我尝试给图像一个蓝色,给 div 一个红色背景,它总是红色,所以 div 太高了。 It just ignores every fixed height I give.它只是忽略了我给出的每个固定高度。 I already read about using display: top but none of it worked.我已经阅读了有关使用display: top的信息,但没有一个起作用。 What exactly is the problem here?这里到底有什么问题? On a HTML-Page everything is just fine.在 HTML 页面上,一切都很好。

Try adding width:100%;尝试添加width:100%; height:100%; object-fit:cover; to the image.到图像。 Hope it works for you.希望对你有效。

 <div style="border: 5px solid black; height: 115px;"> <div style="width: 29%; height: 115px; float: left; background-color: red;"> <img src="https://via.placeholder.com/150" alt="Bild 1" style="width:100%; height:100%; object-fit:cover;"> </div> <div style="width: 55%; float: left; padding-top: 60px; font-size: 18px; font-weight: bold;"> SOME TEXT </div> <div style="float: right; width: 16%; font-size: 18px; padding-top: 10px;"> <div style="float: left; width: 25px;">ANOTHER TEXT</div> </div> </div>

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

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