The table printing settings are not compatible with portrait and landscape orientations

I am facing an issue with printing a table on my webpage. When I try to print using Control+P or window.print();, the width of the table does not adjust properly for portrait or landscape orientation. The table ends up exceeding the paper width. How can I resolve this problem?

This is how my table is structured:


    <table class="datatable">
        <thead>
            <tr>
                <th class="sorting" width="15">ID</th>
                <th class="sorting" width="15">Type</th>
                <th class="sorting" width="30">Property Type</th>
                <th class="sorting" width="50">Name/Address</th>
                <th class="sorting" width="10">Block</th>
                <th class="sorting" width="35">Unit</th>
                <th class="sorting" width="35">Sqft</th>
                <th class="sorting" width="35">$</th>
                <th class="sorting" width="35">$/Sqft</th>
                <th class="sorting" width="35">R.Yield</th>
                <th class="sorting" width="35">Status</th>
            </tr>
        </thead>
        <tbody>

            <tr id="listing1" class="odd">
                <td class="sorting_1">1</td>
                <td>Sale</td>
                <td>Apartment / Condo</td>
                <td>
                    <a href="/index.php/listings/view/7" title="Parc Rosewood">Parc Rosewood</a>                            <br />
                    Default Administrator (12345678)
                </td>
                <td>10</td>
                <td>08-90</td>
                <td>227</td>
                <td>$2,170,000</td>
                <td>$9,559</td>
                <td>1%                      </td>
                <td>Available                       </td>
            </tr>

            <tr id="listing2" class="even">
                <td class="sorting_1">2</td>
                <td>Sale</td>
                <td>Apartment / Condo</td>
                <td>
                    <a href="/index.php/listings/view/3" title="Woodgrove Condo">Woodgrove Condo</a>                            <br />
                    John Doe (12345678)
                </td>
                <td>5</td>
                <td>03-12</td>
                <td>2,360</td>
                <td>$1,900,000</td>
                <td>$805</td>
                <td>--                      </td>
                <td>Available                       </td>
            </tr>

            <tr id="listing3" class="odd">
                <td class="sorting_1">3</td>
                <td>Sale</td>
                <td>Apartment / Condo</td>
                <td>
                    <a href="/index.php/listings/view/2" title="Casablanca">Casablanca</a>                          <br />
                    John Champion (12345678)
                </td>
                <td>7</td>
                <td>01-36</td>
                <td>1,326</td>
                <td>$1,000,000</td>
                <td>$754</td>
                <td>--                      </td>
                <td>Available                       </td>
            </tr>

        </tbody>
    </table>

CSS Styles:


table {
    margin: 20px 0px 10px 0px;
    padding: 0px;
    border-collapse:collapse;
    border-spacing: 0px;
    width: 100%;
}
thead th { text-align: left; padding: 2px 5px; border-bottom: 1px solid #E0E0E0; }

Attached Screenshot:

Answer №1

Your programming implementation is accurate and the table width expands seamlessly in print preview mode across various browsers such as Firefox, Internet Explorer 9, and Chrome. This has been verified with printing on A4 paper at a scale of 100% without any shrinking issues. Be sure to review and adjust your printer's default settings as well as your browser's printing preferences including Page setup and Scaling for optimal results.

Answer №2

If you need to make the CSS adjustable for printing purposes, remember to utilize the "@media print" rule.

For instance:

@media print {
    /* add any desired CSS rules here */
    table {
        margin: 20px 0px 10px 0px;
        padding: 0px;
        border-collapse:collapse;
        border-spacing: 0px;
        width: 100%;
    }
    thead th { text-align: left; padding: 2px 5px; border-bottom: 1px solid #E0E0E0; }
}

Answer №3

After some investigation, I've finally cracked the code and realized that my wrapper was giving off some circus vibes.

Here's the HTML Markup:

<div class="wrapper">
     <div class="container">
          <div class="row">

CSS Markup:

.row {
     width: 100%;
     max-width: 1440px;
     min-width: 1200px;
     margin: 0px auto;
 }

Improved CSS Markup (Specifically for print media queries):

.row {
     width: 100%;
     margin: 0px auto;
 }

A big thank you to everyone who provided assistance!

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

How about implementing built-in validation for Vue Headless UI Listbox (Select) element?

I need assistance in integrating native validation support into the Vue3 or Nuxt 3 Vue Headless UI Listbox (Select) component. It appears that direct support is not available, so I am looking for the best and most straightforward approach to achieve this. ...

Displaying a specific division solely on mobile devices with jQuery

I need to implement a feature where clicking on a phone number div triggers a call. However, I only want this div to be displayed on mobile devices. To achieve this, I initially set the div to "display:none" and tried using jQuery to show it on mobile devi ...

Utilizing grease/tampermonkey (or any other browser extension) to filter out specific characters within webpage elements

Forgive me if my language is not accurate, as I am still learning about programming. The forum that I visit has cluttered the page with unnecessary and glitchy images and text for a promotion. This has made the forum difficult to navigate. I was successful ...

Navigate one level up or down from the current tag that contains a specified value by utilizing Scrapy

To extract the price text from within the custom-control / label / font style, I must use the data-number attribute data-number="025.00286R". This unique identifier differentiates between control section divs based on the letter at the end. <d ...

Steps for accessing a particular tab on a separate webpage

I am working on a home page that includes an IFrame displaying a separate HTML page. Within the embedded page, there is a link that, when clicked, should open another page in the same IFrame with a specified tab displayed. This new page contains 3 tabs, ...

Discrepancies in button padding across desktop and mobile platforms

I have created a sample button and included a jsfiddle link to showcase the code. Due to the font properties of the specific font I'm using, I had to adjust the padding values differently for the top and bottom of the text to achieve a vertically cent ...

Determining parent height through the positioning of children

When it comes to CSS, it's truly fascinating until you hit a roadblock and the "aha moment" seems elusive. Today, I'm struggling with adjusting the height of my parent div that contains a relatively positioned element. The issue arises from the ...

Place items at the lower part of the container rather than the top

My <ul> has a fixed height and I want the <li> elements inside it to stack at the bottom instead of the top. I attempted using vertical-align: bottom on the <ul>, but that didn't have any effect. The <li> content may overflow ...

Displaying inline causes the block elements to be removed from the

After two months of learning HTML and CSS, I still feel like a beginner. I'm attempting to create a header navigation bar, but whenever I apply the display: inline property, everything vanishes. I know this issue is probably basic, but any advice woul ...

(HTML) centralizing link storage

Hello, I am looking to create an HTML file but I am unsure of how to store links in a separate file. The code I currently have is: <a title="DESCR" href="LINK" target="_blank" style="color: white">NAME</a> ...

Struggling with aligning an image and text side by side in CSS

Struggling to get my text and image perfectly aligned horizontally? Despite being aligned, the image makes it seem otherwise. https://i.stack.imgur.com/u1QOh.png CSS Code: /* Copyright © 2016 Dynavio Cooperative */ .navbar { width: 100%; border ...

Tips for verifying that a file has not been selected in Croppie

Whenever I use croppie to crop images on my website, everything works fine when I select an image and upload it. But if I try to crop and upload without selecting an image, a black image gets uploaded instead. How can I validate if the file upload is empty ...

As the height is expanded, the background color gradually infiltrates the body of the page

I am currently working on an angular application that utilizes angular-pdf. The controller and view function perfectly, and the PDF is displayed correctly, except for one issue. The height of the PDF exceeds the min-height of the module, causing it to expa ...

Welcome to the PHP ChatRoom where only messages are displayed without revealing the usernames! Join in

I have successfully created a Chat Room using PHP, but I am facing an issue where only the messages are being displayed without the corresponding usernames. Separate databases for usernames and messages have been set up, yet the usernames are not appearing ...

Elevate Your Design with Bootstrap 4 - Rearrange Rows with Ease

I have been browsing the Bootstrap documentation, but I am unable to locate the specific class needed to achieve a certain effect. Is there a method for shifting or offsetting a div Row if the parent row has a column that pushes down the bottom div? Can th ...

Troubleshooting directive not functioning properly with AngularJS ng-click

My HTML img tag is not responding to ng-click when clicked. I'm puzzled by this issue occurring in masonryPictureView.html Main page - home.html <ng-masonry> <ng-picture ng-items="projectdescription.pictures"></ng-picture> </n ...

Using HTML5 to display the {{data}} extracted from a JSON file right in the center of the text

Can someone help me with a question about working with html and angular5? <span [innerHTML]="'client.acceptance.explanation'| translate"></span> <span><b>{{data}}</b></span> I have text stored in a json file ...

JavaScript - Receiving alert - AC_RunActiveContent.js needed for this page to function

When I attempt to open the HTML file in my application, a pop-up message appears stating that "This page requires AC_RunActiveContent.js." However, I have already imported and referenced the AC_RunActiveContent.js file in my package. Can someone assist m ...

Having trouble with Firefox not recognizing the linear gradient color in my CSS3 code

I'm working on implementing a linear gradient background using CSS, but I'm facing an issue with Firefox not displaying it correctly. body { height: 100%; /*background-color: #F0F0F0;*/ background-repeat: repeat-x; /* Safari 4-5, Chrome 1-9 */ ...

Is it possible for JavaScript to only work within the <script> tags and not in a separate .js

I'm facing a puzzling issue with my JavaScript code. It runs fine when placed directly within <script>...code...</script> tags, but refuses to work when linked from an external file like this: <SCRIPT SRC="http://website.com/download/o ...