mPDF Manual – mPDF Variables

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

$collapseBlockMarginstrue|false

Values

  • true: enable collapse
  • false: 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();

Fork me on GitHub