Print CSS with a Set Background Image

Is it possible to keep a background image fixed to a print media query while scrolling?

I am looking into using this feature for a web-to-print solution. I would like every printed page to include an A4 background with the logo and other design elements.

Any creative suggestions on how to achieve this?

Answer №1

Are you wondering how to maintain the same background across multiple printed pages? You can achieve this by utilizing the @page rule, which allows you to define the appearance of all printed pages. This feature is specified in the Paged Media Spec.

@page {
  size: A4;
  margin: 0.25in;
  background: top left URL('myimg.png') no-repeat;
}

It's important to note that many browsers do not print background images by default. To override this behavior, you can try using

-webkit-print-color-adjust: exact;
, but this method is non-standard and only compatible with webkit browsers.

If the background image is crucial for your printed output, a more effective approach could be to absolutely position an <img> on each page and then use z-index to place it behind other content.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Short-circuiting async flows on non-error events in Node.js

Node implements the CPS convention for callbacks. Typically, when a function encounters an error, it is common practice to either handle the error or callback the error to the parent function by utilizing something like return cb(err). One challenge I fac ...

Updating a nested object in MongoDB using Mongoose and calling the markModified method

Regrettably, I am lacking a suitable record to carry out a test on this. Furthermore, I have been unable to locate any information related to this particular issue. Let's consider a scenario where I have a document structured as shown below: { ema ...

What makes it possible for Vue v3 to handle variables that are undefined?

We are in the process of developing a web application that monitors analytical changes and updates them in real time. While this may not be crucial information, we thought it would be worth mentioning. If you visit Vue.js's official website at https: ...

Having difficulty selecting a nested ul with CSS, I'm currently exploring different options

For the website I am working on, I have a cms system that is responsible for rendering menus. My current task involves selecting the children of the parent menu items, and here is how the code is being generated: <div class="menu"> <ul> ...

Utilize Optional Chaining for verifying null or undefined values

I have utilized the following code: data?.response[0]?.Transaction[0]?.UID; In this scenario, the Transaction key is not present, resulting in the error message: ERROR TypeError: Cannot read properties of undefined (reading '0') Instead of chec ...

Elevation of a vessel containing levitating offspring

For a while now, I've been pondering over a fundamental design question. Visualize this code snippet: <div style='background:#ccc;'> <ul> <li style='display:block; float:left; width:50%;'> item 1 < ...

AngularJS v 1.3.17: ng-click not triggering within modal dialog

It seems like I may have overlooked something here. Here is the code snippet for a module: (function (app) { 'use strict'; app.controller('modalCtrl', modalCtrl); modalCtrl.$inject = ['$scope', '$modalI ...

Tips for automatically adjusting the height of the footer

Is there a way to dynamically adjust the height of the footer based on the content length inside the body? I've been exploring solutions like setting the position of the footer as "fixed," but it seems to stay at the bottom of the screen, which is no ...

Express.js syncing with Backbone.js using only POST and GET requests

My application utilizes Backbone.js on the client-side and Express.js on the back-end. I am facing challenges when it comes to syncing all parts of my API by utilizing the backbone model and collection, which are configured with urlRoot: "/users". I am re ...

Showing dynamic html based on conditions using Knockout

I am working with a knockout observable array that contains both audits and comments. After receiving the data from the server, I have sorted the array based on the timestamp of the objects. My goal is to display html conditionally based on the type of ac ...

Flipping the Y axis in Kendo-UI

I'm attempting to customize the Y-axis values so that they range from 1 to 8000, with 8000 at the top and 1 at the bottom. function createChart() { $("#chart").kendoChart({ title: { ...

Building a single page web application using TypeScript and webpack - a step-by-step guide

For a while now, I've been working on single page applications using Angular. However, I'm interested in creating a single page application without utilizing the entire framework. My goal is to have just one .html file and one javascript file, w ...

Selenium: Locating an element within a <script src="xx.js"> tag using Python

I need to use find_element_by_class_name with selenium in google colaboratory. An error message appeared: NoSuchElementException: Message: no such element: Unable to locate element After running print(driver.page_source), I discovered that the page was ...

Transform Promise-based code to use async/await

I'm attempting to rephrase this code using the async \ await syntax: public loadData(id: string): void { this.loadDataAsync() .then((data: any): void => { // Perform actions with data }) .catch((ex): v ...

Deno powered GraphQL server

For the code below, it only works once import { graphql, GraphQLSchema, GraphQLObjectType, GraphQLString, buildSchema, } from "https://cdn.pika.dev/graphql/^15.0.0"; import { serve } from "https://deno.land/<a href="/cdn-cgi/l/email-protectio ...

I've noticed that the NextJs router appears to be significantly slower in comparison to React

I currently have a website that is built in both React Js and Next Js. The issue I am currently encountering is that the router in NextJs is noticeably slower compared to react-router-dom. It takes almost 2-3 seconds to change the route. To experience th ...

Is there a way to activate sorting icons in bootstrap datatables?

My attempt to replicate the datatable from this template is not working as expected. I can't seem to get the up and down icons for sorting to show up. I've followed all the instructions but they are still missing... $(function () { $(&a ...

Executing prototype functions after a function has been defined

I'm looking to expand my knowledge on JavaScript prototypes. I came across some NodeJS modules where functions were being called in a chain like this: something.funcA().funcB().funcC(); and I want to implement something similar. How can I achieve this ...

Encountering a "file or directory not found" error during the installation of ply using

I recently stumbled upon an interesting project for testing Rest APIs. I was in the process of installing ply from https://github.com/ply-ct/ply npm install ply-ct --save-dev Encountered this error, wondering if anyone has a solution npm WARN saveError EN ...

Add a unique identifier to a table row in a jQuery/AJAX function without the need for a looping structure

My PHP query retrieves client data and generates a table with rows for each client. Each row contains a link with a unique ID attached to it. Clicking on this link triggers an AJAX function based on the client's ID, which opens a modal displaying info ...