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

Can floating elements be disregarded by block elements?

According to W3C, the behavior of floating elements is such that: When a float is present, non-positioned block boxes that come before and after the float flow vertically as if the float doesn't exist. However, line boxes positioned next to the fl ...

Issue with webpack failing to detect css-loading module

My application functions properly when using yarn, however, I encounter an issue with loading the CSS when incorporating a benchmarking library called react-benchmark, which utilizes webpack. You can find a minimal example of the entire project here: https ...

Switch from monochrome to color when hovering inside a clipping mask

I have successfully mastered the technique of changing an image from grey to color on hover using CSS and JavaScript. However, I am curious about whether it is possible to achieve the same effect using a clipping mask. Attached is an image that illustrate ...

utilizing Javascript to insert a class with a pseudo-element

Witness the mesmerizing shining effect crafted solely with CSS: html, body{ width: 100%; height: 100%; margin: 0px; display: table; background: #2f2f2f; } .body-inner{ display: table-cell; width: 100%; height: 100%; ...

Dropdown menu in Bootstrap gets cropped behind a scrollable container

I am encountering a problem with my Bootstrap Drop Down. The dropdown is located within a scrollable div with a fixed height. Whenever I click on the dropdown, the menu appears behind the scroll content. However, a normal select works perfectly fine. htt ...

Trouble with state updates in React/React Native?

Despite feeling silly, I have been struggling with the state not updating despite hours of troubleshooting. Below is my simple useEffect code: const [notificationData, setNotificationData] = useState(null); useEffect(() => { messaging().getIn ...

Is there a way to configure gulp-sass to compile the actual bootstrap CSS styles instead of just echoing the import statement?

I recently embarked on a project where I wanted to utilize the Sass bootstrap source (.SCSS), apply some customizations (through another .SCSS file), and generate a CSS output. To achieve this, I decided to employ Gulp in VS2019 with gulp-sass. After goin ...

How to Display MUI Autocomplete in React with freeSolo Mode and Dropdown Arrow

Just jumping into MUI and could use some guidance. I'm trying to implement <Autocomplete freeSolo ...> with a dropdown arrow icon similar to combo-box mode. Seems like the popupIcon and forcePopupIcon props aren't working in freeSolo mode ...

Looking to show a div upon clicking a link with the use of Javascript

Looking for a workaround due to restrictions on using alert or any Js dialog box, I need to create some sort of magic trick: 1. Create a div with a link named "info". 2. Develop an invisible div that will serve as my "PopUp" containing random information. ...

Delaying consecutive calls to query on mouse enter event in React

Currently, I have a React component from antd that utilizes the onMouseEnter prop to make an API query. The issue arises when users hover over the component multiple times in quick succession, which floods the network with unnecessary API calls. To prevent ...

Use CSS to activate a sibling div when hovering over a button within the same div that contains the button

Is it possible to change the color of div #panel when hovering over the button #button inside div #left? #left #button:hover~#panel { background-color: blue; } #panel { position: absolute; float: r ...

Is implementing React.memo recommended for my messaging application?

Is it detrimental to chat apps if I save chats in my memo every time new messages arrive? ...

JavaScript: Changing the names of all object keys

As a beginner, I am struggling to rename some objects in my key using a map function. Below is my current array: "platforms": [ { "id": 6, "name": "PC (Microsoft Windows)" }, { "id": 11, "na ...

Creating a sticky popup feature for your Chrome extension

Just starting out with chrome extensions and looking to create one that appends an external class to a selected tag. For example, let's say we have the following tag: <h1>extension</h1> When the user clicks on this element, I want to ad ...

While working in Next.js, I utilized an `<Image />` tag with a link to an image, only to encounter an unexpected error

I've attempted it numerous times, but the error persists. I even went ahead and created the next.config.js file. module.exports = { images: { domains: ['link.papareact.com', ], }, }; Error: The src prop (https://links.pap ...

How to Align React Material UI Grid with Varying Row Counts in Each Column

Objective My goal is to design a component that showcases details about a device, including an icon and its current status. For instance: Approach I've Taken I am attempting to accomplish this by structuring a MUI Grid in the form of a 2x2 grid la ...

Display only distinct elements retrieved from an array depending on the checkboxes selected

I'm currently facing a problem for which I can't seem to find a solution. I have a situation where I need to display checkboxes for contact types in an array. When I pass a certain type (let's say TA), I want to display the checkboxes for th ...

I'm looking for guidance on effectively utilizing filter and map within the reducers directory to manipulate the workouts objects

I am encountering an issue while trying to send delete and update requests for the workout object. The error message indicates that the filter function is not compatible as it's being applied to an object instead of an array. Here is the snippet of co ...

What is the best way to make two buttons align next to each other in a stylish and elegant manner

Currently, I am diving into the world of glamorous, a React component styling module. My challenge lies in styling two buttons: Add and Clear. The goal is to have these buttons on the same row with the Clear button positioned on the left and the Add button ...

Glass-pane or angular/HTML overlay on a designated element

Is there a way to create a glass-pane effect, like an hourglass symbol on a semi-transparent layer, within the boundaries of an HTML element E? The goal is to have the glass-pane only overlap the area within E's boundaries. When the glass-pane is ac ...