collapseBlockMargins
(mPDF ≥ 4.2)
collapseBlockMargins – Specify whether to collapse (vertical) margins between block elements
Description
void collapseBlockMargins
Specify whether to collapse (vertical) margins between block elements. In line with CSS specification, the top/bottom margins of adjoining block-style elements are collapsed to the larger of the two. This works between all block elements such as DIV, P, H1-6 etc. and also lists and tables.
NB Firefox does not collapse margins above and below tables, but IE8 does.
Values
$collapseBlockMargins = true
|false
Values
true
: enable collapsefalse
: disable collapse
Default: true
Changelog
Version | Description |
---|---|
4.2 | Variable was added. |
Examples
<?php
// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$html = '
<div style="margin-bottom: 3em;">This DIV has a bottom margin defined as 3em</div>
<div style="margin-top: 2em;">This DIV has a top margin defined as 2em. The
space between these DIVs will collapse to 3em</div>';
$mpdf->WriteHTML($html);
$mpdf->Output();
Note: The collapse of margins at the top and bottom of the page is unaffected by this variable.
This is set by the custom CSS property margin-collapse: collapse|none
which can be defined in the defaultCSS
configuration variable