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

Display/Modify HTML form

Looking for advice on how to create an interactive HTML form that displays data and allows users to edit it by clicking 'Edit' before submitting changes. Any suggestions on how to implement this functionality? ...

Design images with rounded corners using CSS

I'm looking to design an image avatar similar to the contact avatars on Skype. Can someone assist me with this? I have tried using border radius-boundary, but I haven't had much luck. ...

Can you explain the distinction between using element~element versus element+element?

Can you explain the variation between these two CSS selectors? When using them, I seem to receive the same outcome. In the HTML: <div>One</div> <p>Two</p> CSS Example #1: div+p { background:red; } This code assigns a red backgr ...

ReactJS: Want to update card design by utilizing the onClick event handler

Currently, I am aware that there will be a need to refactor this code later on to separate things into their own components. However, due to time constraints, I have to wire this up as is at the moment. To achieve this, I utilized array.map() to create car ...

Change the class of the div when the first div is selected

My goal is to switch the class of the #klapp element (from .klapp to .klappe) whenever a click event happens inside the #label-it container, including when the #klapp element itself is clicked. The challenge is that I am not able to use unique IDs for each ...

Formatting HTML Output Using PHP

Looking to format html output sourced from a database using php and facing an issue: Desired Format: ... <li> <div class="row-wrapper"> <div class="some-class-1">ARRAY-ELEMENT-1</div> <div class="some-class-1" ...

Is it necessary to treat headings within figure elements as document headings?

Imagine a scenario where we are working with a page structured like this: <!DOCTYPE HTML><HTML><BODY> <ARTICLE> <H1>Heading Example</H1> <P>Here is what a heading (level 2) looks like:</P> <FIG ...

Identifying clicks on various indices within a common class or element

My website has a navigation menu with unordered list items in it. <nav> <ul> <li id="zero"></li> <li id="one"></li> <li id="two"></li> </ul> </nav> I am working on implementing J ...

What could be the reason for the inconsistent behavior of onClick, causing it to occasionally fail to display the associated

I just started using typescript 2 days ago, mainly to create a custom component for my streamlit app. I've made a navigation bar with a tab that can be clicked on the sidebar, but it's displaying some erratic behavior. Sometimes when I click on t ...

Implementing Google Fonts into Next.js with the combination of Sass, CSS, and Semantic UI React

I have set up my next.config.js file with the following configuration: const withSass = require('@zeit/next-sass'); const withCss = require('@zeit/next-css'); module.exports = withSass(withCss({ webpack (config) { config.module. ...

Is there a way to deactivate other dropdown options?

To simplify the selection process, I would like to disable the options for "Province", "City", and "Barangay". When the user clicks on the "Region" field, the corresponding "Province" options should be enabled. Then, when a specific province is selected, t ...

"When you hover over an element, extra information will pop up that only pertains to that specific element and will not impact any surrounding

As I dive into the world of HTML and CSS, I've come across a hurdle when it comes to hovering over divs and displaying hidden elements. The goal is for the card to change color on hover (which I've achieved), expand in size, and reveal hidden con ...

Customizing SVGs for Ion Icons Version 5 in a React Application

I have been using ion icons in React by importing them directly into my index.html. While this method has been working well with the icons from ion icons found here, I know that you can also use custom SVGs by specifying an src attribute in the ion-icon ta ...

Is it acceptable to conceal items by utilizing display:none?

When dealing with a dynamic website that includes components from various plugins, is it acceptable to hide elements temporarily or permanently using display:none? Sometimes clients may request certain items to be hidden from the page, so instead of removi ...

Utilizing CSS to Target IDs Using Classes

Recently, I came across a captivating video on YouTube demonstrating how to create a transitional gallery (http://www.youtube.com/watch?v=4sVTWY608go). Inspired by the tutorial, I attempted to implement a similar slider... However, I now have a new idea. ...

Controlling the page scroll when adding data using jQuery

I am encountering an issue with a webpage that displays around 20 pictures in separate divs stacked vertically. Below these 20 pictures, there is a "show more" button that, when clicked, loads another set of 20 pictures and appends them to the existing dat ...

Different ways to alter the color of contextual color classes in Bootstrap 5

Currently working on my project with Bootstrap 5, I've been incorporating elements featuring classes such as btn-primary and text-success. In Bootstrap, the -primary class is associated with blue, while -success corresponds to green, among others. I&a ...

Is it possible for the relative path of a gif image to become invalid when added to a div?

Question Context: In the view, I have a form that will show a loading 'spinner' gif when a user submits it. The Problem: If I place the spinner img element within its container div, the spinner is always displayed, which is not desired: https ...

Preserve selected option in select box after page refresh in JSP

I'm working on a jsp page that contains a simple select html element. Right now, when I select an option and click the Wyswietl button, the page refreshes, the table data is refreshed, but the selected option resets to default... How can I make it sta ...

In the production mode, Nuxt styles may not be properly applied

After working on this project for about four months, everything seems fine in the development version. However, once I build the project and upload it to the server, some of my styles are not applied. For more information, I have imported styles both in c ...