Building an HTML table with predetermined measurements

Looking for Table Dimensions for A4 Print

I am trying to create a table with specific dimensions for A4 print. The requirements are as follows:

  • The first and last rows of the table must have a margin of 11 mm from the top and bottom edges of the paper
  • There should be no margin between the rows
  • The rows of the table must be positioned 4 mm from the left and right sides of the paper
  • There should be a 2 mm gap between every column
  • Each cell in the table should have a width of 38 mm and height of 21.2 mm
  • The table should have 13 rows and 5 columns, totaling 65 cells

Here is a JSFiddle link: http://jsfiddle.net/tt13/ZjBrV/

Question

What steps can I take to achieve the table layout described above?

Detailed

The HTML table structure I am using is shown below:

<body>
  <table>
    <td> 
     <div class="bcell">
      sample text2<br/>
      <img src="..."/><br/>
      sample text2
     </div>
     </td>
   ....
  </table>
</body>

Despite using the following CSS to achieve the desired A4 print dimensions, the result is not as expected:

        body {      
            padding:11mm 4mm 0 4mm;
            background: white;
            font-family: Arial;
            width: 210mm;
            font-size:3mm;
        }

        table { 
            page-break-after:always;
            width: 100%;
            height: 275mm;
            margin:0 auto;
            page-break-inside:avoid;                 
            border-collapse: collapse;

        }

        td img {
            height:10mm;
        }

        td {
            width: 38mm;
            height:21.2mm;
            padding: 0 1mm 0 1mm;
            font-style: bold;
            text-align: center; 
            vertical-align:middle;
        }


        tr    { 
            page-break-after:auto;
            page-break-inside:avoid; 
            height:21.2mm;
            margin:0;
            padding:0;
            page-break-inside:avoid;             
        }

Answer №1

It appears that you are in need of a printable output with critical dimensions, possibly for printing on kiss-cut label sheets or a similar medium. Achieving pixel-perfect results across all browsers and operating systems with an HTML solution seems unlikely. Two possible approaches to consider include:

  1. Creating the grid as an image and displaying it on the webpage for printing.
  2. Generating the grid as a downloadable PDF for printing purposes.

Most server-side environments offer libraries for both of these options. From my own experience, option #2 tends to yield superior results.

Answer №2

It has been found that applying Css may not effectively adjust the width of table cell elements. A suggested workaround is to enclose the cell's content within a div or span, then utilize td:first-child in the css to specify the width. Another alternative is to explore the css table model.

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

Adding a Table Row in jQuery without Appending it to the Bottom of the Table

I am working on a project that involves an HTML Table where the user can add a new Row by clicking a button. However, I want the new Row to be added not at the end of the table, but after the last row of input fields. To demonstrate, I have prepared a sam ...

Achieving a transparent inner box-shadow effect on hover: a step-by-step guide

Is there a way to make the black ring transparent upon hover by changing box-shadow: 0 0 0 5px #000, 0 0 0 10px green to box-shadow: 0 0 0 5px transparent, 0 0 0 10px green? It doesn't seem to be working for me. Any suggestions on how to achieve this ...

What is the best way to extract data from several SQL tables and display it in an HTML/PHP table?

In my database named result, I have two tables named res and sub. Here is an example of the contents in the res table: sno regno name sub1 sub2 sub3 sub4 sub5 1 1DU12CS100 student1 70 80 85 70 90 2 1DU12CS101 ...

Issue with jQuery animation: Background color does not change upon scrolling

Here is my fiddle link: https://jsfiddle.net/jzhang172/owkqmtcc/5/ I am attempting to change the background color of the "content" div when scrolling anywhere within it. The goal is for the background color to change when scrolling and revert back to its ...

Ensuring text is perfectly centered within a div, regardless of its length

In the quest to center text of unknown length within a div, challenges arise. Constraints limit its size to a certain extent, making it unclear whether one or two lines will be needed. As such, traditional methods like line-height are not viable options. A ...

a Bootstrap 4 element lacking any line-styling

Is it possible to create a link that appears as plain text with no underline, using minimal css? The issue at hand is that the <a> tag defaults to a blue color and adds an underline on hover, making it look like a typical link. I would like it to re ...

Is there a method to ensure equal alignment of the <div class="card"> elements in Bootstrap?

I need help figuring out how to align this card uniformly with the others: https://i.sstatic.net/x2wZ2.png In the image below, you can see that the card for the top reason for downtime doesn't match the other cards. I want them all to be the same he ...

Ensure the navbar includes the .container class and insert an extra dropdown right next to the container without causing any misalignment

Desired output: Achieve two rows with a .container div, centered in the viewport and aligned with each other. The second row should contain the navbar within a .container. Additionally, add a non-collapsing dropdown at the end of the navbar row, outside th ...

Replace the default disc icon with a more detailed icon for UL lists

I am working with an unordered list and I want to use <details> to show a sublist for one of the items: <ul> <li><details> <summary>details bullet</summary> <ul> <li>detail 1</li> ...

What is the best method for choosing the parent elements?

I am attempting to create a sidebar that saves the last clicked link in local storage and still displays the collapsed links after the page is reloaded. $(".clickedLink").parent().parent().css('background-color', 'green'); Ca ...

Transforming the appearance of web elements using jQuery (graphic)

While there are numerous resources on changing CSS with jQuery, I seem to be having trouble getting my image to hide initially and show up when a menu tab is clicked. Any help would be greatly appreciated! ;) h1 { text-align: center; } .Menu { widt ...

Tips for shifting nested div containers to the left as the content expands

I have a div containing a dropdown menu, label, and button as shown below: <div class="container "> <div id="User"> <div id="BtnUser"> <div id="dropMe"> <div class="dropdown"> <a onclick="User ...

Guide on implementing CSS3 parser with HtmlUnitDriver

As an example, let's consider a scenario where we have a selector to target the active menu item: $("ul#menu li a[href='/']") And a selector to target the remaining menu items (1): $("ul#menu li a:not([href='/'])") However, the ...

The Angular Material Theme is not being properly displayed on the mtx-datetimepicker component

Issue: While using directives from ng-matero for DateTime with Angular Material for application design, the dateTimepicker element is not applying the angular material theme as desired. https://i.sstatic.net/zPBp3.png Code Example The app.module.ts file i ...

What is the best way to incorporate content just out of view below the parallax section that becomes visible as you scroll?

Check out this amazing parallax effect: https://codepen.io/samdbeckham/pen/OPXPNp <div class="parallax"> <div class="parallax__layer parallax__layer__0"> <img src="https://github.com/samdbeckham/blog/blo ...

What is the best way to ensure that only one div is toggled at a time while using the toggle class function?

$(document).ready(function(){ $("#items").children().click(function(){ $(this).toggleClass('clicked'); }); }); .clicked { background-color:red; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></s ...

What are some effective strategies to ensure my header is aligned properly on both mobile and desktop platforms?

While I'm more focused on back end web development, I've been struggling to make my header look good on both mobile and desktop without resorting to creating separate sites for each. This approach has proven to be cumbersome as maintaining two si ...

What is the best way to position this span on the right side of the div?

Here is some HTML code snippet: <div class="title"> <span>Cumulative performance</span> <span>20/02/2011</span> </div> This is the corresponding CSS: .title { display: block; border-top: 4px solid #a7a ...

Scrolling up the page following the addition of a new row

https://i.sstatic.net/QLBEe.png Description After clicking the plus button in the image above, a new row is created using jQuery autocomplete. https://i.sstatic.net/Xf5Et.png Description The image above illustrates the page displaying when scrolled to t ...

Using CSS files that are not properly imported into React components

Currently, I am utilizing multiple CSS files for a specific purpose. The issue I am facing is that when I apply styles to one component in a CSS file, it inadvertently affects other components as well, not just the intended one. I believe the root of this ...