Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda