What is the method for achieving a table with 100% height in HTML?

I have a row of 5 tables, each with 100% height that displays correctly in the browser - the elements fill all available space. However, in print view, they do not stretch as desired.

https://i.sstatic.net/9d1cg.png

I am looking to have the table extend beyond the page break while maintaining the header. I attempted using a single table with one column, but due to varying card heights, it did not work properly. Any changes made, even unrelated ones, would disrupt the layout entirely.

Edit: Due to document size constraints, I cannot provide the full implementation, but here is a minimal example:

<style>
  .flex {
    display: flex;
    gap: 1rem;
    margin-top: 50vh; 
  }

  table {
    flex: 1;
  }

  .card {
    padding: 0.5rem;
    border-radius: 0.25rem;
    background: lightblue;
  }
</style>
    
<div class="flex">
  <table>
    <thead>
      <tr>
        <td>
          <div style="background: red">COLUMN1</div>
        </td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>
          <div class="card">CARD</div>
        </td>
      </tr>
      <!-- more cards -->
    </tbody>
  </table>
  <!-- more tables [1..5] -->
</div>

In print view, the tables only expand to the total height of the cards inside, unlike in the browser where they are stretched.

https://i.sstatic.net/ST4vc.png

https://i.sstatic.net/pZtX1.png

Answer №1

To achieve the same number of cells in each table, you can insert empty cells and set a cell height to maintain the grid structure.

https://i.sstatic.net/aqKfw.png

CSS Style

td {
  height: 2rem;
  line-height: 1;
}

.flex {
  display: flex;
  gap: 1rem;
  /* add some top margin to simulate content before the table */
  margin-top: 50vh;
}

table {
  flex: 1;
}

.card {
  padding: 0.5rem;
  border-radius: 0.25rem;
  background: lightblue;
}
/* new style */
td {
  height: 2rem;
  line-height: 1;
}
<div class="flex">
  <table>
    <thead>
      <tr>
        <th>
          <div style="background: red">COLUMN1</div>
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>
          <div class="card">CARD</div>
        </td>
      </tr>
      <!-- more rows -->
    </tbody>
  </table>
  <table>
    <thead>
      <tr>
        <th>
          <div style="background: red">COLUMN2</div>
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>
          <div class="card">CARD</div>
        </td>
      </tr>
      <!-- more rows -->
    </tbody>
  </table>
</div>

Answer №2

A few years back, I encountered a similar situation where I had to figure out how many rows could fit on a printed page. I decided that 10 rows was the right amount, so I cut the table every 10 rows and started a new one.

For each new table, I included the code

style="page-break-before: always;"
and that solved the problem.

This method helped me avoid various rendering issues, gave me the option of adding headers on each page or not, and allowed me to choose whether to include all table headers or just the expanding one.

Answer №3

It is imperative to specify a height value for the div in order to achieve this.

Give this a shot:

body, html{height:100%}
div{height:100%}
table{background:green; width:450px}  

Please inform me if you found this guidance beneficial.

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

Flexbox's bootstrap columns display issue on smaller screens with no wrapping

I am currently working on a section of my website where I have applied some CSS to 2 divs and an anchor tag in order to center the content vertically. However, I am facing an issue with the flex style properties when the window size is less than 768px. In ...

Encountered an error while trying to filter markers and list using Knockout and Google Maps - Uncaught TypeError: Unable to locate property 'marker' of undefined

I am looking to enhance user experience by implementing a feature where clicking on a marker or a city name will display the info.window specific to that marker. HTML: <!DOCTYPE html> <html> <head> <title>Exploring Mag ...

What's the best way to display two checkboxes on a single line?

I am working with checkbox filters in WooCommerce and I want to organize them so that two checkboxes appear in one row, followed by the next two in the second row, and so on. The issue can be seen at this URL. I also want this style to apply to "Product Co ...

Assign a unique HTML attribute to a child element within a Material-UI component

Currently, I am trying to include the custom HTML5 attribute "data-metrics" in the span element within the ListItemText Material UI component. However, I am facing some difficulty achieving this as per the specifications outlined in the Component API Docum ...

Dilemma: Overlapping Dropdowns on a Bootstrap Navbar Floated right

When using Bootstrap 3.2 and applying navbar-right to two different dropdown menus, they tend to overlap slightly. The code snippet below is taken directly from the Dropdown examples on the official Bootstrap website, but with the modification of having tw ...

Color-coding HTML table cells depending on the SQL flag value

After successfully constructing a SQL query that incorporates three conditions from my database table and sets a flag based on them, I have made progress in my project. The query looks like this: UPDATE staging SET `miuFlag` =1 WHERE `lowSideMIUNumAr ...

Vuetify Container with a set maximum width that remains fixed

I recently started developing a web application using Vue.js and Vuetify (https://vuetifyjs.com/en/). Currently, I have a basic layout with 3 columns. However, I noticed that the width of these columns is restricted to a maximum of 960px due to some defau ...

Transform ajax functionality into jquery

I need help converting an AJAX function to a jQuery function, but I'm not sure how to do it. function convertToJquery() { // Create our XMLHttpRequest object var hr = new XMLHttpRequest(); // Set up variables needed to send to PHP file var ur ...

Are HTML5 Track Element Cue Events Working Properly?

My goal is to dynamically assign functions to HTML5's cue.onenter events. This feature is relatively new and currently only supported in Chrome with specific flags enabled (Refer to the example on HTML5 Rocks here). However, I seem to be facing some ...

Ways to retrieve the child number using JavaScript or PHP

Is there a way to retrieve the child number upon clicking? View screenshot For example, when I click on the X button, I want to remove that specific element. However, this action should only apply to item n2. In order to achieve this, I need to determine ...

Move the element that can be dragged with the identifier X to the designated drop area with the identifier

I am attempting to create a function that will allow me to drag a draggable element and drop it into a designated container using their IDs. However, I am unsure of how to get started. dropToContainer("myDraggable", "div3"); function dropToContainer(co ...

Switching the keyboard language on the client side of programming languages

I'm interested in altering the keyboard language when an input element changes. Is it possible to modify the keyboard language using client-side programming languages? And specifically, can JavaScript be used to change the keyboard language? ...

Update JSON data in ng-blur event using AngularJS

Could you offer some guidance on how to push the content from a text box into JSON when I click outside of the box? Below is the code for my text box: <input type="text" name="treatmentCost" class="form-control" ng-model="addTemplate" /> And here i ...

Guide on integrating an HTML and CSS register form in Django

I have successfully created a responsive register and login using HTML and CSS. Instead of utilizing the standard register form and login provided by Django upon configuration, I want to apply my own custom template. To summarize, while I am familiar with ...

Contrasting one-finger scrolling versus dual-finger scrolling on a touch device with IE11

Can you explain the distinction between scrolling using one finger versus two fingers in IE11? I have noticed that I am able to scroll/pan the webpage with just one finger on certain elements, while on other elements, I need to use two fingers on a Micros ...

Enhance User Experience in IE11 by Providing Font Size Customization with Angular (Using CSS Variables)

I am in the process of developing an Angular application. One of the requirements is to allow the user to choose between small, medium, or large font sizes (with medium being the default) and adjust the font size across the entire webpage accordingly. Wh ...

Excessive padding observed on the right side of the screen when viewed on mobile devices

I am having an issue with my portfolio site where there is a white space on the right side in the mobile view, but only in Chrome. The desktop and Mozilla mobile views are fine. I have attached a screenshot highlighting the problem. Here is the link: Chrom ...

Rearrange divs from left to right on mobile display

I need help creating a header bar with three elements as shown below https://i.sstatic.net/4njuk.png When viewed on mobile, I want the menu (toggle-icon) to shift left and the logo to be centered. I attempted using push and pull with no success. Is there ...

Issues with the functionality of jQuery append and AngularJS ng-if not functioning

In my application using checkboxes, I control the visibility of charts with the ng-if directive and implement drag-and-drop functionality with angular-Dragula. The use of ng-if is essential for me as it allows me to manipulate visible div IDs and organize ...

Error message indicating that the event "OnkeyDown" is not in sync within the React application

Hey everyone! I'm a beginner in web development and I'm struggling to understand why the event "OnKeyDown" is triggered the second time. My task involves changing (increasing, decreasing) parts of a date (day, month, year, hour, minutes, seconds) ...