Print Button
In a previous government job, we needed a print button that targeted specific content without the extraneous fluff of a webpage. About the same time, BricksExtras introduced a feature in their sharing buttons that targeted a specific area, so it was super easy to implement. I have been working on a print button today (AI helped with the JS) and have created a similar function. You add the button to a page and wrap the content to be printed in a class (.print-me by default). The global CSS sets up print styles and hides a duplicate title box by default (the script cannot find all instances of the target class). The CSS also exposes any URLs for accessibility (it’s hard to click a link on paper).
Global CSS
.print-me {
& .title-box {
display: none;
}
}
@media print {
.fw-print-no-print {
display: none !important;
}
.fw-print-preserve-ancestor {
display: block !important;
margin: 0 !important;
padding: 0 !important;
border: none !important;
box-shadow: none !important;
}
.title-box {
display: block!important;
}
@page {
size: letter;
}
body {
margin: 0;
padding: 0;
}
body,
p,
h1,
h2,
h3,
h4,
h5,
h6,
li {
font-family: Helvetica, Arial, sans-serif;
font-size: 12pt;
font-weight: normal;
color:#000;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: bold;
margin-top: 0.5em;
margin-bottom: 0.5em;
}
h1 { font-size: 24pt; }
h2 { font-size: 18pt; }
h3 { font-size: 14pt; }
a:any-link {
color: #0000ff;
text-decoration: none !important;
font-weight: bold;
}
a:any-link::after {
content: " (" attr(href) ") ";
color: #000;
font-weight: normal;
font-family: Menlo, Consolas, Monaco, "Liberation Mono", "Lucida Console", monospace;
font-size: 10pt;
}
img {
width: 100%;
}
.pagebreak {
clear: both;
break-before: page;
page-break-before: always;
}
}
AI Statement
AI assisted with JS.
Changelog
1.0.0Initial release.
ACSS Usage
Automatic.CSS (ACSS) is used in most components and patterns, but in the event you aren't using it, you should be able to easily update the CSS if you are not using it.
Usage
This work is marked CC0 1.0 Universal