Who the document is between / Bill-to and ship-to pair
Bill-to and ship-to blocks side by side that stay level
Two address blocks presented as a pair, where one is who pays and the other is where it goes, and the pair has to stay legible when the two are the same and when they are wildly different lengths.
Why this block is harder than it looks
Two blocks side by side, each of variable height, is a layout that goes wrong in three ways. If they are floated, the shorter one leaves a hole and the next block wraps around it. If the labels are inside the blocks, the labels stop aligning as soon as one address is a line longer. And there is a semantic problem that the layout cannot solve on its own: when the two addresses are identical, printing both is not helpful, it is noise, and the reader has to compare five lines against five lines to establish they are the same.
The decisions that make it work
Reasons rather than a description of the code. Each of these is a choice that has a wrong answer, and the wrong answer is usually the default.
- Use a two-column grid with align-items: start, so the blocks sit on the same top line regardless of height and neither one drags the other down.
- Put the labels in their own row of the grid rather than inside each block, so they align with each other and not with the first line of variable content.
- When the two addresses are equal, print the ship-to block as a short reference to the bill-to rather than a copy of it. Saying the same as billing is one line and is instantly readable.
- Give the pair break-inside: avoid, because splitting a bill-to block across a page while its ship-to counterpart stays behind is the most confusing possible outcome.
- Keep a fixed gutter in absolute units rather than a percentage, so the gap does not change with page size.
- If the document may be posted in a window envelope, the addressee block belongs in the fixed window position instead and this pair belongs lower down. Those are two different blocks with two different jobs.
The fragment
Markup and the CSS it needs, and nothing else. It expects a document that already has a page rule and a base stylesheet, so paste it into one rather than opening it on its own.
<section class="parties">
<h3 class="label">Bill to</h3>
<h3 class="label">Deliver to</h3>
<address class="addr">
<span class="line name">Wynne and Hall Ltd</span>
<span class="line">Unit 4, Callow Works</span>
<span class="line">Sheffield S3 8NP</span>
</address>
<address class="addr">
<span class="line name">Wynne and Hall, Depot 2</span>
<span class="line">Attn: Goods In</span>
<span class="line">Farrier Road</span>
<span class="line">Rotherham S60 1AB</span>
</address>
</section>
<style>
.parties {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 12mm; /* absolute, so it survives a page change */
align-items: start; /* tops level, whatever the heights */
break-inside: avoid;
margin: 10pt 0;
}
.parties .label {
margin: 0 0 3pt;
font-size: 8pt;
letter-spacing: 0.06em;
text-transform: uppercase;
color: #555;
}
.parties .addr { font-style: normal; line-height: 1.35; }
.parties .addr .line { display: block; }
.parties .addr .name { font-weight: 700; }
</style>What breaks when it is built the obvious way
Floating the two blocks. Floats are removed from the flow, so the taller one determines nothing and the content after the pair rides up beside the shorter one. It looks correct whenever the two addresses happen to be the same height, which in test data they usually are.
How to prove it survived pagination
Render with a two-line bill-to next to a six-line ship-to, then swap them. Both ways the labels should be level, the blocks should start on the same line, and whatever comes next should start below both. Then render with the two addresses identical and read what it says.
Where it sits in a finished document
This page is one block. The document it belongs to has a page rule, a base stylesheet, a header and everything else around it, and repeating all of that here would make thirty pages that say the same thing. The packing slip template is a complete file with this block already in it, so take that and change the fragment rather than assembling one from parts. The property doing most of the work here is covered on its own page, with the support caveats that belong there rather than here.
Frequently asked
Will this fragment work on its own?
Not as a whole document. It has no page rule, no margins and no base type, because those belong to the document rather than to the block, and duplicating them in every fragment would mean thirty copies to keep in step. Paste it into a template that already has them.
Why does it look right in a browser and wrong in the PDF?
Because a browser window is one continuous surface and a document is a stack of fixed rectangles. Nothing in a scrolling view exercises a page boundary, so every break rule in the fragment is inert until the content is paginated. Render the real thing with enough content to cross two or three boundaries, then look.
Do I need a special option on the render request for this?
No. Everything on this page is CSS and markup, which is your side of the boundary. What the render has to give you is a real page size with real margins, and after that the layout is decided by the stylesheet.
Other parts of a document
The blocks that sit next to this one, and one from the next group along so you are not sealed inside a single kind of problem.
Positioning an address so it shows through an envelope window
An addressee block placed at an exact position on the page so it lines up with the cut-out in a standard window envelope when the sheet is folded.
A contact block where the long email address does not break the layout
Phone, email, reference number and website, usually set small under a name or in a footer, and usually the block that overflows first.
A delivery details block with dates, carrier and terms
Dispatch date, expected arrival, carrier, consignment reference and delivery terms, gathered into one block near the top of a despatch document.
A bank details block that can be transcribed without errors
Account number, sort code or routing number, IBAN and BIC, set so that a person copying them into a banking screen gets them right the first time.
Packing slip, as a complete file
The whole document with this block already in place, ready to copy and change.
break-inside in paged output
The property carrying the weight here, with its real support status.
Every part of a document
The full list, grouped by the kind of problem the block poses.
Paste the fragment into the playground inside a page rule and see what it does at a real page size. That is the only way any of this gets confirmed.