Can the content be duplicated following a page break? Is there a way to identify when a page break occurs?

My webpage is quite long and often requires multiple page breaks when printed. However, this causes the content to be separated from the parent layout structure, making it difficult for users to understand which question it corresponds to. This issue is illustrated below:

Current Scenario

A 1 i   What is the capital of Peru?
    ii  What is the capital of Brazil?
    iii What is the capital of Equador?
  2 i   What is the population of France?
    ii  What is the population of Spain?
___________________________________________
    iii What is the population of Italy?

To address this problem, I would like to repeat the question numbers at the beginning of each page so that even if a question is on a separate page, it still has a clear reference.

Desired Outcome

A 1 i   What is the capital of Peru?
    ii  What is the capital of Brazil?
    iii What is the capital of Equador?
  2 i   What is the population of France?
    ii  What is the population of Spain?
___________________________________________
A 2 iii What is the population of Italy?

Is there a way to achieve this using CSS? The 'page-break' properties don't seem suitable for this situation. Alternatively, could Javascript be used? Note that I will be converting the HTML to PDF using wkhtmltopdf.

An example code snippet has been included as follows:

td, th {
  vertical-align: top;
}
<!DOCTYPE html>
<html lang="en>
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>

<table style="height: 202px; width: 557px;">
  <thead>
  <tr>
    <th>Main</th>
    <th>Sub</th>
    <th>Subsub</th>
    <th>Question</th>
    <th>Marks</th>
  </tr>
  </thead>

  ... (code continues)

</tbody>
</table>

</body>
</html>

Answer №1

The following code snippet utilizes a responsive grid system along with the CSS property page-break-inside.

In essence, we are specifying the value of the page-break-inside property as avoid, meaning that the entire item will be displayed on the same page without breaking across multiple pages. This ensures that the complete item stays intact within a single page.

To achieve this layout, we encapsulate the main group within a single div and apply the page-break-inside property. For creating a tabular structure, we leverage the CSS grid system by defining rows and columns.

This code ensures that in scenarios where there is a page break, only the main question number and sub-question number aren't duplicated but all questions under the same main question remain together on one page.

For dynamic population of content on each page, you can consider implementing this code using for loops.

Finally, take note of the usage of the print CSS class. It is used to designate the row where a new main question is being created. If you find the implementation intricate, feel free to reach out for guidance on designing the loop structure...

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

Using GreenSock to animate and manipulate the tween function's parameters

I have two functions that are called on mouse events: function menuBtnOver(e){ var b = e.data; b.setPosition(b.x, b.y+5); } function menuBtnOut(e){ var b = e.data; b.setPosition(b.x, b.y-5); } Additionally, there is another function: setP ...

Tips for preventing a div from overflowing in col-md-12 in Bootstrap 3

Is there a way to maintain the same width for the image and div below? Everything looks good until the window size is between 545px to 575px. The .header width changes only at col-md-12. How can I preserve the aspect ratio? VIEW SCREENSHOT CODEPEN LINK ...

Exploring MVC 5's View and Controller Components

In my GetCourseList.cshtml file (view), I have the following code that displays fetched information from the database: @model IEnumerable<WebApplication8.Models.Courses> @{ Layout = null; } <!DOCTYPE html> <html> <head> ...

Utilizing jQuery and AJAX to dynamically include multiple PHP pages

My webpage contains a div tag similar to this structure: <div class="ajax-load"> <!-- First.php: jquery-slider-1 jquery-widget-1 second.php: jquery-slider-2 jquery-widget-2 --> </div> There is also a ...

Is it possible for a CSS Transition/Transform to ease out smoothly yet not ease in at all?

It appears that the transition is smoother when I stop hovering over the button, compared to when I actually hover. Why might this be? .button_1 { border-width: 0.8px; border-color: Lightgray; background-color: hsla(209, 72%, 59%, 0.85); ...

jsx eliminate parent based on dimensions

Imagine I have a DOM structured like this <div className="parent"> <div>child 1</div> <div>child 2</div> </div> If the view is on mobile, I would like the DOM to transform into <div>child 1</ ...

Tailored design - Personalize interlocking elements

I am currently working on a custom theme and I am trying to adjust the font size of Menu items. In order to achieve this, I have identified the following elements in the tree: ul (MuiMenu-list) MuiListItem-root MuiListItemText-root If I want to modify th ...

Exploring the process of loading a new page in the browser through nodeJS

I'm a beginner looking to load a new page in the browser with just a button click. I've tried some code, but it's not working as expected. Here's what I have: NodeJS file: var http = require('http'); var fs= require('fs ...

Leverage JavaScript to insert the text of an HTML element attribute into another HTML element

Is there a way to access the message using JavaScript in order to write it to the heading tag? Below is my HTML code: <h1 message = "this is the title of the page"></h1> The message needs to be displayed under specific conditions. I ...

display the HTML form when the page is clicked

Trying to implement an onclick method for selecting form types. I have multiple form types available - example here Clicking on one submenu should open up the desired form type directly below the menu How can I dynamically load a form based on the select ...

Divs are shown as the user scrolls, not only when they are in view

Currently, I am in the process of enhancing my online portfolio by integrating a bar graph feature. However, I have encountered an issue with its functionality. The goal is for the bar graph to display only when it comes into view during scrolling. Althoug ...

Difficulties with Bootstrap, JQuery, HTML, and CSS

Currently in the process of revamping a university society's website, I have some experience in web development but nothing too advanced. You can view the current website here: . Here is a sneak peek at the new design I am working on: . However, I& ...

How to create a custom CSS style to make Bootstrap 4 modal slide in from the bottom

Back in the days of Bootstrap 3, this was the trick: .modal.fade .modal-dialog { -webkit-transform: translate3d(0, -25%, 0); transform: translate3d(0, -25%, 0); } Another approach that could have been used: .modal.fade .modal-dialog { transfor ...

Creating a horizontal split with HTML's div tag and CSS

Can someone assist me in creating two horizontal divisions using the <div> tag in HTML? I have been struggling to achieve this and would appreciate any help with utilizing HTML and CSS for the task. ...

What is the best way to add an Apple iPhone-like effect to a menu list?

I've been working on creating a menu similar to the Apple menu using the greensock api Here is my progress so far: JSFIDDLE Update This is what I am aiming for: Fiddle Any idea why there is flickering when hovering over it? <div class="de ...

I am attempting to generate dynamic checkboxes from an array that update on a daily basis

Hello, I'm a newcomer here so if I make any errors, please forgive me. Currently, I am facing an issue with my JavaScript code. It works perfectly when it is structured as a list using <ul> and <li> tags. However, when I attempt to convert ...

Showing a tooltip on the right side of a control with an arrow pointing towards it in a colored

Can someone help me with displaying a tooltip to the right end of a control, with the arrow facing the same direction and changing the background color of the arrow to red? Here is my attempt so far <input id="age" title="test tooltip"> $( documen ...

Transforming data from PHP JSON format into HTML output

Struggling to convert JSON data into HTML format? Having trouble maintaining the correct order of child elements in your structure? Here's a solution: Take a look at this example JSON: { "tag": "html", "children": [ { "ta ...

Content in TinyMCE styled with the default CSS of the application

Hello fellow developers; I'm struggling to find a suitable solution to apply the same styles from our main CSS file to the text entered in the TinyMCE editor. Just to clarify, I don't want to alter the overall theme or appearance of TinyMCE itse ...

The hover effect becomes disabled once the slider is toggled

My table has a feature where I can change the background color and other elements using a slider. However, I'm facing an issue where the hover effect on the table stops working when I toggle the slider on or off. I attempted to solve this with a funct ...