DOMPDF有两个div并排? PHP

时间:2016-05-21 19:02:58

标签: php

我正在使用DOMPDF来制作发票。我需要和几个div并排。浮动元素不起作用。我想把第2列放在第1列

之后
<?php
require_once "dompdf/dompdf_config.inc.php";

$dompdf = new DOMPDF();

$html ='
<html>
<link type="text/css" href="pdf.css" rel="stylesheet"/>
 <body>

<div class="columns">
    <div class="red" >Column 1</div>
    <div class="grey">Column 2</div>
    <div class="red" >Column 3</div>
</div>
<div class="clear"></div>

 </body>
</html>
';

$dompdf->load_html($html);
$dompdf->render();

//$dompdf->stream("hello.pdf");

$dompdf->stream('my.pdf',array('Attachment'=>0));

?>

以下是CSS

div.columns       { width: 50%; }
div.columns div   { width: 50%; height: 100px; float: left; }
div.grey          { background-color: #cccccc; }
div.red           { background-color: #e14e32; }
div.clear         { clear: both; }

1 个答案:

答案 0 :(得分:0)

添加外部样式表路径:

$dompdf->set_base_path('(FilePath)/pdf.css');

在:$dompdf->render();

请注意,CSS选择器在dompdf中区分大小写。

阅读http://code.google.com/p/dompdf/wiki/CSSCompatibility或Git https://github.com/dompdf/dompdf/wiki/CSSCompatibility

参考DOMPDF doesn't work with external css file

CSS not working with DOMPDF