Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
Losing CSS styling upon printing

I am using a style sheet to properly print out a webpage. The webpage has fields sat next to each other but upon printing these fields no longer sit next to each other but instead cascade down the sheet. I have created a style sheet but I'm not sure exactly how that is supposed to stop this from happening unless I hard code into the style sheet what I want to happen. Unfortunately I can't do that because I need to print out several different pages that have different layouts. Is there any way to fix this?

function removeLinks(printDiv) {
            var all_links = document.getElementById(printDiv).getElementsByTagName("a");

            for (var i = 0; i < all_links.length; i++) {
                all_links[i].removeAttribute("href");
            }
        }

        function printdiv(printDiv) {
            var divCaseNote = document.getElementById(printDiv);
            var oldstr = document.body.innerHTML;
            var oldTitle = document.title;

            if (divCaseNote != null) {
                divCaseNote.style = "padding: 20px;";
                innerHTML = divCaseNote.innerHTML;
            }

            removeLinks(printDiv);

            var headstr = "<html><head rel=\"stylesheet\" media=\"all\" link href=\"/CSS/style.css\"/><title> </title></head><body>";
            var footstr = "</body>";
            var newstr = document.all.item(printDiv).innerHTML;
            document.body.innerHTML = headstr + newstr + footstr;
            document.title = oldTitle.replace(" - View Case Note", "");

            window.print()

            document.body.innerHTML = oldstr;
            document.title = oldTitle;

EDIT: A snippet of the html output of this function. It holds all the correct divs for the columns but instead of printing the columns side by side they print cascading down the page.

<div class=\"view-value\" style=\"border-left: none;\">
   Jerry</div></div></div>
   <div class=\"col-md-3\"><div class=\"media-body\">   
      <div class=\"view-label\">Participant's Last Name</div>
        <div class=\"view-value\" style=\"border-left: none;\">Field</div>

What it should look like [What it should look like][1]

What it actually looks like after printing What it actually looks like after printing

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is that the inline styles are getting obliterated by this statement:

            divCaseNote.style = "padding: 20px;";

which removes all the style attribute and replaces it with just the padding.

To add/alter the padding but nothing else you want to change just that property so try:

            divCaseNote.style.padding = "20px";
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!