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

303
Views
How to keep table elements fixed with JavaScript

I want the tags inside the table to be fixed when printing. The code I wrote works well in View, but when printing in JavaScript, if one of the columns is large, the rest of the columns go in the middle but I want everyone to stay on top I used position: fixed but the table crashed.

<script>


    function printDiv() {
        var divToPrint = document.getElementById('table');
        var htmlToPrint = '' +
            '<style type="text/css">' +
            'table th, table td,table tr {' +
            'font-family:B Nazanin;'+
            'border:0.1em solid #000;' +
              'text-align:center;' + 
            
            'font-size:14px;' +
            'padding:0.2em;' +
            '}' +
            '</style>';


        htmlToPrint += divToPrint.outerHTML;
        newWin = window.open("");
        newWin.document.write(htmlToPrint);
        newWin.print();
        newWin.close();
    }



</script>

enter image description here

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

0

You need to use vertical-align: top; to make the content in each cell. display at the top.

<style>
            .table-bd{
                border-collapse: collapse;
                border: none;
                width: 200px;
            }
            .table-bd td{
                border: 1px solid #CCCCCC;
                word-wrap: break-word;
                word-break:break-all;
                width: 50px;
                height: 80px;
                vertical-align: top;
            }
        </style>

<table class="table-bd">
            <tr>
                <td>asdfasdfasdf</td>
                <td>asdfasdfasdfasdfasdf</td>
            </tr>
            <tr>
                <td>asdfasdfasdf</td>
                <td>qwerqwerqwerqwerqwer</td>
            </tr>
            <tr>
                <td>erwtewyrettyrety</td>
                <td>tyuirtyiuiytugfhdfgh</td>
            </tr>
        </table>

enter image description here

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!