MALIKA KAROUM

MALIKA KAROUM

  • Home
  • Inleiding
  • Unite Arab Emirates
  • Blog
  • video’s
  • Promotion
    • Worth for free now
    • Work from Home 2023
    • Gadgets
    • All about Windows
    • about Whatsapp
    • Whats the
    • About websites
    • New Ways
    • New Way of Watching
    • Virtual
    • Website
    • All about Video
    • How to Use
    • YouTube Info
    • All about Twitter
    • The Best of
    • About Apps
    • Google News
    • For Free
    • About This
    • Need More
    • Why should you
    • Iphone news
    • Interesting News
    • About Amazone
    • Some tips
    • About Netflix
    • All about Music
    • About Facebook
  • Marketing
    • Malika Karoum Strategie Modules
    • Malika Karoum Online Marketing
    • Malika Karoum Business Service
    • Malika Karoum Marketing Platform
    • Online business marketing
  • Luxury
    • The Indulgence Business site
    • The Luxury Web site
    • The Ultimate Indulgence
    • The Indulgence Site
    • The Ultimate Luxury Information site
    • Online luxury
  • Malika Karoum
    • Malika Karoum LinkedIn
    • Malika Karoum Facebook
    • Malika Karoum Instagram
    • Malika Karoum Business News
    • Adverteren grote fraude
    • Menu POS
    • Malika Karoum Evenementen
  • Security
  • Malika Karoum link
  • Home
  • Malika Karoum Global News
  • Using CSS to Format Documents for Printing
June 8, 2023

Using CSS to Format Documents for Printing

Using CSS to Format Documents for Printing

by Malika Karoum / Thursday, 24 December 2020 / Published in Malika Karoum Global News

If you’ve ever printed off ticket reservations or directions to a hotel from the web, you’ve probably been less than impressed with the results. You may, therefore, be unaware that printed documents can be styled in much the same way that they can on-screen, using Cascading Style Sheets (CSS).

Separation of Concerns

A key benefit of CSS is the separation of content from presentation. In the simplest terms, this means instead of very old-fashioned stylistic markup such as:

<font size="7"><b>Heading</b></font>

We use semantic markup:

<h1>Heading</h1>

Not only is this much cleaner, it also means our presentation is separated from our content. Browsers render h1 elements as large, bold text by default, but we can change that style at any time with a stylesheet:

h1 { font-weight: normal; }

By gathering those style declarations in a separate file, and referencing that file from our HTML document, we can make even better use of separation. The style sheet can be reused, and we can change that single file at any time to update the formatting in every document that uses it.

Including a Print Style Sheet

In a similar manner to including a screen style sheet, we can specify a style sheet for print. A screen style sheet is typically included like so:

<link href="base.css" rel="stylesheet" />

However, an additional attribute, media, allows targeting based on the context in which the document is rendered. By default, the previous element is equivalent to:

<link href="base.css" rel="stylesheet" media="all" />

This means the stylesheet will be applied for any medium the document is rendered in. However, the media attribute can also take values of print and screen:

<link href="print.css" rel="stylesheet" media="print" />

In this example, the print.css stylesheet will only be used when the document is printed out. This is a very useful mechanism. We can gather all common styling (perhaps font family or line spacing) in a stylesheet that applies to all media, and media-specific formatting in individual stylesheets. Again, this is another use of separation of concerns.

Some Example Style Declarations

A Clean Background

You almost certainly don’t want to waste ink printing out a colorful background or a background image. Start by resetting any defaults for these values that may have been set in your document:

body {
background: white;
color: black;
}

You might also want to prevent any background images from printing—these should be decorative and, therefore, not a required part of your content:

* {
background-image: none !important;
}

Related: How to Set a Background Image in CSS

Controlling Margins

Another obvious point to consider regarding print is the page margin. Whilst CSS provides a means of setting margin size, you should bear in mind that your browser and printer may also influence margin settings themselves.

For example, in Chrome’s print dialog, there is a margin setting that has values including none and custom which will override anything specified via CSS:

For this reason, it’s recommended to leave margin decisions to the reader on public webpages. However, for personal use, or for creating a default layout, setting print margins via CSS may be appropriate. The @page rule allows margins to be set, and should be used as follows:

@page {
margin: 2cm;
}

CSS also has the capacity for more sophisticated print layouts, such as varying the margin according to whether the page is an odd-numbered one (right), even-numbered (left), or the cover page.

Unfortunately, this is poorly supported—especially the cover page option—but it can be used to a minimal extent. The following styles produce pages with slightly larger bottom margins than top and slightly larger margins on the outer page edge than the spine:

@page {
margin-left: 20mm;
margin-right: 20mm;
margin-top: 40mm;
margin-bottom: 50mm;
}
@page :left {
margin-left: 30mm;
}
@page :right {
margin-right: 30mm;
}

Hiding Irrelevant Content

Not all content will be suitable for a print version of your document. If your page includes banner navigation, advertisements, or a sidebar, you might want to prevent those details from appearing in the print version, for example:

#contents, div.ad { display: none; }

Fixing links

Hyperlinks are obviously not relevant in printed material, so you’ll probably want to remove any styles which differentiate them from surrounding text:

a { text-decoration: none; color: inherit; }

However, you might still want readers to have access to the original URLs, and a straightforward solution is to automatically insert them after the linked text:

a[href]:after {
content: " (" attr(href) ")";
font-size: 90%;
color: #333;
}

This CSS gives results such as the following:

a[href]:after specifically targets the position after (:after) each link element (a) that actually has a URL ([href]). The content declaration here inserts the value of the href attribute between brackets. Note that other style rules can be applied to control the display of the generated content.

Handling Page Breaks

To avoid page breaks leaving isolated content, or breaking it awkwardly in the middle, make use of the page-break properties: page-break-before, page-break-after and page-break-inside. For example:

table { page-break-inside: avoid; }

This should help to keep tables from spanning multiple pages, providing none are taller than a single page. Similarly:

h1, h2 { page-break-before: always; }

This means that such headings always start a new page. It might cause problems if you immediately follow your page’s h1 with an h2, though, since the h1 will end up on a page all on its own. To avoid this, simply cancel the page break using a selector that targets that specific instance, for example:

h1 + h2 { page-break-before: avoid; }

Viewing Print Styles

In all cases, your browser and operating system should provide a print preview feature, often as part of the standard print dialog.

The Chrome browser makes it more convenient to check and even debug your print styles via Developer Tools, as demonstrated by this example showing a CV with a print style sheet. First, open the main menu and select More Tools followed by the Developer Tools option:

From the new panel that appears, select Menu, then More tools, followed by Rendering:

Then scroll down to the Emulate CSS media type setting. The dropdown allows you to toggle between the print and screen views of your document:

When emulating the print stylesheet, the standard Styles browser is available to inspect and modify the live style rules. Bear in mind that emulating print output on a screen is still not 100% accurate. The browser knows nothing about paper size, and the @page rule cannot be emulated.

Printing to a PDF

A handy feature of modern operating systems is the ability to print to a PDF file. In effect, anything you can print can, instead, be sent to a PDF file—no real surprise since a PDF file is supposed to represent a printed document, after all.

This makes HTML, in combination with a print stylesheet, an excellent means for creating a high-quality document that can be sent as an attachment, as well as printed.

Print a Variety of Documents

You can use a print stylesheet to create quality documents, including anything from your CV to recipes or event announcements. Web pages typically look ugly and contain unwanted details when printed, but a small number of style tweaks can dramatically improve print results. Saving the final results as a PDF is a quick way to create attractive, professional documents.

MakeUseOf – Feed

  • Tweet
Tagged under: Documents, Format, Printing, Using

About Malika Karoum

What you can read next

11 Android Apps You Need for Traveling the World
5 Websites That Save Old Sounds, Maps, Newspapers, Music, and Books
8 Time-Saving Automator Workflows for Your Mac

Malika Karoum Blog 2023

  • How to Delete the Last 15 Minutes of Your Google Search History

    There’s a quick way for you to clear your...
  • Lenovo Wants You to Know Its Yoga Pad Pro Can Be Used as a Portable Switch Display

    Sometimes, when playing with your Nintendo Swit...
  • The 5 Best Apps for Buying and Selling Pre-Owned Books

    We’ve all been at the point where we have...
  • Humble’s Recent "Heal Covid-19" Bundle Raised 1.2 Million for Charity

    To help raise money for COVID-19 relief in Indi...
  • Nintendo Partners With PlayVS to Make Its Games Recognized High School Varsity Athletics

    It’s odd—Nintendo gets a lot of flak for ...
  • The Pros and Cons of Playing Video Games on an Emulator

    If you’re a fan of playing retro video ga...
  • 5 Curators to Find the Best Articles Worth Reading on the Internet

    When anyone and everyone is a publisher, it isn...
  • Apple Could Unveil iPads With OLED Screens in 2023

    Apple only just switched from LCD to mini-LED d...
  • What Is Signal and How Does It Work?

    The chances are that you use at least one of th...
  • Samsung’s Upcoming Flagship Exynos Chipset Will Feature AMD’s RDNA2 GPU

    AMD confirmed its partnership with Samsung at C...
  • Atari Finally Reveals the Launch Date for the New Atari VCS Console

    At last, after what seems like an age (it pract...
  • Twitter Starts Testing Full-Screen Ads in Fleets

    Twitter has announced that it will be adding fu...
  • When Is Facebook Messenger Going to Offer End-to-End Encryption?

    Facebook Messenger is easy to use and has great...
  • Get Paid to Play Apps: How They Work and What You Risk

    You’ve probably seen advertisements for a...
  • When Will PS5 Production Ensure Supply Meets Demand?

    Despite the PS5’s launch taking place in ...
  • How to Manage Processes on Ubuntu Using System Monitor

    Linux, like most modern operating systems, is v...
  • How to Get Verified on Twitter and Finally Get That Blue Check Mark

    Twitter, like most social media platforms, offe...
  • 10 Street Photography Tips That Will Make You a Better Photographer

    Street photography is enjoyed by many enthusias...
  • Huawei Freebuds 4i Review: Quality ANC Earbuds for $100

    Huawei Freebuds 4i 8.00 / 10 Read Reviews Read ...
  • What Is Extended Reality (XR) and How Does It Work?

    We’re living in a digital age where the virtual...

MALIKA KAROUM ONLINE MARKETING PLATFORM

Office:
RME HOLDINGS SARL – DUBAI BRANCH

BUSINESS CENTER

Parcel ID: 345-835

Area: Bur Dubai

Sub Area: Burj Khalifa

UNITED ARAB EMIRATES

 

 

 

Malika Karoum Concept

Malika Karoum Projects

  • GET SOCIAL

© 2014 Malika Karoum -United Arab Emirate Dubai- All Rights Reserved

TOP