Enhancing react-to-print functionality for optimal performance across various browsers and mobile platforms

Currently, I am developing a sample react-to-print resume template to be included in a larger portfolio website. While testing the page on Chrome and Edge browsers on a laptop, everything seems optimized. However, there are issues when using Firefox; the background color in the .name-contact class turns white, causing the content to overflow onto the next page upon clicking the print button. My goal is to ensure that the resume template fits neatly on one page across all browsers.

In addition, the print preview appears differently on mobile browsers compared to laptops. I aim to achieve consistency in the print preview across all browsers and devices.

I am unsure whether this challenge stems from a CSS or a react-to-print-related problem.

You can find the hosted resume template on GitHub pages here: spencertimothy.github.io/React-to-print-example

Below is the CSS code for the @media print query:

 @page {
    margin: 0;
    padding: 0;
  }


  button {
    display: none;
  }


  .my-resume {
    width: auto;
    /* max-width: 100%; */
    color: black;
    margin: .5cm;
    font-size: 10pt;
    background-color: white;
    box-shadow: none;
    border-radius: none;
  }

  h4,
  .education>h2,
  .projects>h2,
  .relavent-skills>h2,
  .work-experience>h2,
  b {
    color: black
  }

  h1 {
    font-size: 36pt;
  }

  .name-contact {
    background-color: var(--color-light-grey);
    border-top: 5px solid var(--color-light-blue);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }

  .resume-icons,
  .map-icon {
    color: var(--color-button-blue);
  }

  li>b {
    color: black;
  }
}

Here is a screenshot of the print preview issue on Firefox from a laptop: Firefox laptop print preview

Here is a screenshot of the print preview issue on Safari from a mobile device: Safari mobile device print preview

The following image shows the print preview issue on DuckDuckGo and Firefox browser on a mobile device: DuckDuckGo and Firefox mobile device print preview

Answer №1

If you want to ensure that background styles are retained while printing in Firefox and IE, you can use the following code snippet. This has worked well for me by keeping everything on one page during the printing process.

@media print {
 .my-resume {
    -webkit-print-color-adjust: exact; /* For Chrome */
    color-adjust: exact; /* For Firefox and IE */
  } 
}

Check out this link for reference image.

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

Warning of superfluous escape character when executing 'npm start' on a React application

I have encountered a warning while running my React app using npm start. The warning appears in the terminal and reads as follows: Line 24: Unnecessary escape character: \[no-useless-escape The warning is related to the following code snippet: va ...

Jest is unable to execute tests containing methods within a .tsx file

Typically, I only test files ending with .ts, but this time I have a file containing utility methods that return a react element. Therefore, my file has a .tsx extension and includes components from material ui and other libraries. Initially, I encountere ...

Resize the images and align them side by side

I have a container with a maximum width of 1400px. Inside this container, there are two images of different sizes. I want to align them in a row using flexbox so that they fit within the 1400px width and still maintain a visually appealing appearance as sh ...

What are the steps to achieve a smooth transition from a background-image to transparency?

Take a look at this related image: The goal is to replicate the design shown on the right side of the image. However, there's also a parent container with its own background image, as opposed to a solid color. Any guidance on how to achieve this? U ...

Dropdown menu with CSS arrow

I'm attempting to create something similar to this: Here's what I have so far: Html: <div class="panel-heading" data-toggle="collapse" href="#data2"> <div class="heading"> APPLICATION </div> <span clas ...

Troubleshooting Issue: Unable to Collapse Bootstrap Responsive Navbar Button with Custom CSS Modifications

I recently created a responsive HTML page using Bootstrap, then converted it to WordPress and made some custom CSS adjustments. In the original HTML version of the page, the navbar collapse button worked perfectly when the screen was resized. However, afte ...

The issue persists with Angular's overflow hidden not functioning properly, and similarly, the show password button is

I created a login page using Angular Material, but I'm facing some issues. The problem is that when I set the style overflow: hidden, the show password button stops working. Additionally, if I click the button twice, the webpage refreshes, which shoul ...

Hovering over the Star Rating component will cause all previous stars to be filled

I'm in the process of creating a Star Rating component for our website using Angular 11. I've managed to render the 5 stars based on the current rating value, but I'm having trouble getting the hover styling just right. Basically, if I have ...

Obtain access to global.window.localStorage within getServerSideProps

I have a component that receives props with data and renders the data. In my functionality within the getServerSideProps, I am attempting to retrieve data from localStorage. However, due to window being undefined, I am unable to do so. I have tried using ...

New development: In Express.js, the req.body appears to be empty and req.body.name is showing up as undefined

Something seems off with my code as I am unable to retrieve any data from either req.body or req.body.name. My goal is to extract text from an input field in a React component. Here's the excerpt of my POST request: //posting notes to backend and ...

Modifying the color of a placeholder in an HTML input using CSS

Version 4 of Chrome now supports the placeholder attribute on input[type=text] elements (and likely other browsers do too). Despite this, the following CSS code does not affect the color of the placeholder text: input[placeholder], [placeholder], *[pla ...

Implementing global user authentication state with Zustand in Next.js version 13.4.9

I'm grappling with incorporating zustand into my Next.js 13.4.9 app, specifically for managing global authentication state. Below is the code snippet I have in my application: zustand store: // /src/store/AuthStore.ts import { create } from 'zu ...

Troubleshooting: Why is Jquery unable to retrieve image height?

Having trouble using jQuery to find the actual height of the first image nested within a container. I can access the src attribute but not the height. Any suggestions on how to get the accurate height? Is it necessary to retrieve heights via CSS? Unfortu ...

Surprising automatic scrolling upon pressing the keydown button in Bootstrap

My webpage appears normal with the Bootstrap framework, but whenever I press the down key, the screen scrolls down and displays unexpected white space due to reaching the end of the background-image sized at 1798px * 1080px. Please refer to the image: He ...

Tips for maintaining sequential numbering in Mediawiki sections

Looking to enhance the formatting of numbered lists by adding section headers and restarting numbering? The old Mediawiki format supported this, but it no longer works in version 1.24. For example: ==First Header2== # # ==Second Header2== # Desired output ...

Guide assistance: Imported name does not match component name, but functionality is unaffected

I've been keeping up with the project on GitHub and making some personal tweaks. Although I could probably find the answer on Google or in the documentation, I just can't seem to come up with the right keywords. But one day, I will figure it out ...

Is it possible to make an image gradually appear and disappear?

Is there a way to create a continuous fade in and out effect for an image, transitioning between 40% and 100% opacity? I attempted using a CSS3 opacity property, but it only allows for 0% and 100%, causing the fade effect to be ineffective. Does anyone h ...

Toggle the visibility of an input field based on a checkbox's onchange event

I am facing a challenge where I need to display or hide an Input/Text field based on the state of a Checkbox. When the Checkbox is checked, I want to show the TextField, and when it is unchecked, I want to hide it. Below is the code snippet for this compon ...

How to change the state using an object as an argument in the useState hook within a function

This code uses a function component: export default function Account() { We define a constant with inputs as objects: const [state, setState] = useState({ profile: true, orders: false, returns: false, coupon: false, referrals: false, rewards: ...

Tips for relocating a CSS button

I have designed two buttons using css and I am looking to align them below the title "forecast customer activity". Due to extensive styling in css, the code might appear lengthy. Requesting assistance with a solution after reviewing the following code snip ...