Troubleshooting problems with printing HTML divs and page breaks caused by using float and position styles

Look at this class:

.divDutySlip {
    width: 90mm;
    min-height: 120mm; 
    padding: 2mm;
    /*float:left;
    position: relative; */
    margin: 2mm;
    border: 1px solid #000000;
    page-break-inside: avoid;

}

I've modified two styles. Disabling them allows the content to break correctly across pages. No "Duty Slip" is divided on different pages:

https://i.sstatic.net/844g8.png

If I enable the float and position styles and retry, the page break logic fails. When attempting to print in landscape orientation, the slips are placed side by side but still split at page breaks. In this example with more content, names have been censored:

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

So, how can I fill a page with these slips while preventing them from splitting over page breaks? Currently, the only way I can achieve it is by deactivating those styles and keeping to a single column of duty slips.

CSS:

body {
    font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
    font-size: 12pt;
    text-align: left;
    color: #000000;
    background-color: #ffffff;
}
.divDutySlip {
    width: 90mm;
    min-height: 120mm; 
    padding: 2mm;
    /*float:left;
    position: relative; */
    margin: 2mm;
    border: 1px solid #000000;
    page-break-inside: avoid;

}
.textTitle {
    font-size: 14pt;
    font-weight: 700;
}
.textName {
    font-size: 12pt;
}
.tableDutySlip {
    width: 100%;
    border:1px black solid;
    border-collapse:collapse;
}
.tableDutySlip td {
    border:1px black solid;
}
.cellHeading {
    font-weight: 700;
    background-color: #808080;
}
.cellDate {

}
.cellAssignments {

}
.columnDate {
    width: 25%; 
}
.columnAssignments {
    width: 75%;
}

@media screen
{
    br { display: none; }
}

HTML:

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="SRRSchedule-Duty%20Slips1.css" rel="stylesheet" type="text/css" />
<title>Assignment Duties</title>
</head>

<body>

<div class="divDutySlip">
    <h1 class="textTitle">Assignment Duties</h1>
    <h2 class="textName">Test1</h2>
    <table class="tableDutySlip">
        <colgroup>
            <col class="columnDate" /><col class="columnAssignments" />
        </colgroup>
        <tr>
            <td class="cellHeading">Date</td>
            <td class="cellHeading">Assignments</td>
        </tr>
        <tr>
            <td class="cellDate">Thu, Apr 9</td>
            <td class="cellAssignments">Mic Left, Mic Right</td>
        </tr>
        <tr>
            <td class="cellDate">Sun, Apr 12</td>
            <td class="cellAssignments">Watchtower Reader</td>
        </tr>
        <tr>
            <td class="cellDate">Thu, Apr 16</td>
            <td class="cellAssignments">Mic Left, Mic Right</td>
        </tr>
    </table>
</div>
<div class="divDutySlip">
    <h1 class="textTitle">Assignment Duties</h1>
    <h2 class="textName">Test2</h2>
    <table class="tableDutySlip">
        <colgroup>
            <col class="columnDate" /><col class="columnAssignments" />
        </colgroup>
        <tr>
            <td class="cellHeading">Date</td>
            <td class="cellHeading">Assignments</td>
        </tr>
        <tr>
            <td class="cellDate">Sun, Apr 12</td>
            <td class="cellAssignments">Mic Left, Mic Right</td>
        </tr>
        <tr>
            <td class="cellDate">Sun, Apr 19</td>
            <td class="cellAssignments">Mic Left, Mic Right</td>
        </tr>
    </table>
</div>
<div class="divDutySlip">
    <h1 class="textTitle">Assignment Duties</h1>
    <h2 class="textName">test3</h2>
    <table class="tableDutySlip">
        <colgroup>
            <col class="columnDate" /><col class="columnAssignments" />
        </colgroup>
        <tr>
            <td class="cellHeading">Date</td>
            <td class="cellHeading">Assignments</td>
        </tr>
        <tr>
            <td class="cellDate">Sun, Apr 19</td>
            <td class="cellAssignments">Watchtower Reader</td>
        </tr>
    </table>
</div>

</body>

</html>

Fiddle:

https://jsfiddle.net/e3kradLh/

Answer №1

If you want to consolidate all the duty slips onto a single page, you can create a wrapper div for them and apply a display:flex style. Check out this example on JSFiddle

body {
  font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
  font-size: 12pt;
  text-align: left;
  color: #000000;
  background-color: #ffffff;
}

.wrapper {
  display: flex;
}

.divDutySlip {
  width: 90mm;
  min-height: 120mm;
  padding: 2mm;
  margin: 2mm;
  border: 1px solid #000000;
  page-break-inside: avoid;
}

.textTitle {
  font-size: 14pt;
  font-weight: 700;
}

.textName {
  font-size: 12pt;
}

.tableDutySlip {
  width: 100%;
  border: 1px black solid;
  border-collapse: collapse;
}

.tableDutySlip td {
  border: 1px black solid;
}

.cellHeading {
  font-weight: 700;
  background-color: #808080;
}

.cellDate {}

.cellAssignments {}

.columnDate {
  width: 25%;
}

.columnAssignments {
  width: 75%;
}

@media screen {
  br {
    display: none;
  }
}
<div class='wrapper'>
  <div class="divDutySlip">
    <h1 class="textTitle">Assignment Duties</h1>
    <h2 class="textName">Test1</h2>
    <table class="tableDutySlip">
      <colgroup>
        <col class="columnDate" />
        <col class="columnAssignments" />
      </colgroup>
      <tbody>
        <tr>
          <td class="cellHeading">Date</td>
          <td class="cellHeading">Assignments</td>
        </tr>
        <tr>
          <td class="cellDate">Thu, Apr 9</td>
          <td class="cellAssignments">Mic Left, Mic Right</td>
        </tr>
        <tr>
          <td class="cellDate">Sun, Apr 12</td>
          <td class="cellAssignments">Watchtower Reader</td>
        </tr>
        <tr>
          <td class="cellDate">Thu, Apr 16</td>
          <td class="cellAssignments">Mic Left, Mic Right</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="divDutySlip">
    <h1 class="textTitle">Assignment Duties</h1>
    <h2 class="textName">Test2</h2>
    <table class="tableDutySlip">
      <colgroup>
        <col class="columnDate" />
        <col class="columnAssignments" />
      </colgroup>
      <tbody>
        <tr>
          <td class="cellHeading">Date</td>
          <td class="cellHeading">Assignments</td>
        </tr>
        <tr>
          <td class="cellDate">Sun, Apr 12</td>
          <td class="cellAssignments">Mic Left, Mic Right</td>
        </tr>
        <tr>
          <td class="cellDate">Sun, Apr 19</td>
          <td class="cellAssignments">Mic Left, Mic Right</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="divDutySlip">
    <h1 class="textTitle">Assignment Duties</h1>
    <h2 class="textName">test3</h2>
    <table class="tableDutySlip">
      <colgroup>
        <col class="columnDate" />
        <col class="columnAssignments" />
      </colgroup>
      <tbody>
        <tr>
          <td class="cellHeading">Date</td>
          <td class="cellHeading">Assignments</td>
        </tr>
        <tr>
          <td class="cellDate">Sun, Apr 19</td>
          <td class="cellAssignments">Watchtower Reader</td>
        </tr>
      </tbody>
    </table>
  </div>

</div>

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

VueJS Components experiencing issues with displaying images

Recently, I delved into learning VueJS and successfully created a basic restaurant menu page all within a single file. Excited by my progress, I decided to refactor the project using vue-cli, but hit a snag with the images not displaying properly. The cur ...

Motion of the atoms

I recently came across an interesting effect on the IconArchive website, but I am unsure how to implement it. If anyone could help me understand the concept with a small example, that would be greatly appreciated. You can see the effect in action by visi ...

What is the process for triggering an unordered list when I click on a table data cell within the Hospitals category?

Hi there! I need help with writing a JavaScript function for Hospitals in the code below. When I click on Hospitals, I want to display the values in the unordered list. Expected output: Hospitals--->onclick Bangalore| salem |Goa| Mangalore| Visakhapat ...

I am looking to dynamically insert a text field into an HTML form using jQuery or JavaScript when a specific button is clicked

This is my code snippet: <div class="rButtons"> <input type="radio" name="numbers" value="10" />10 <input type="radio" name="numbers" value="20" />20 <input type="radio" name="numbers" value="other" />other </div> ...

Incorporating a HTML layout with a JS backdrop

I have successfully implemented a JavaScript background and now I want to apply this background across all my PHP files. The issue is that the HTML code either overlaps with the JS content or appears behind it. How can I resolve this? Below is the JS fil ...

Enable the use of custom tags containing hyphens in the kses filter for WordPress

I developed a specialized Wordpress plugin that enables users to incorporate custom HTML element tags (such as <my-element>) into the content of a Post. This allows users without the unfiltered_html capability to utilize predefined custom tags. The ...

Troubleshooting: CSS Selectors Hover Functionality Not Functioning as

I am having an issue where the styling does not change the display to block when hovering. Any insights or feedback would be greatly appreciated. <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="t ...

Switching the Vue image on Routerlink's isExactActive feature

Is there a way to display different images based on whether a link is active or not? <router-link to="/"> <img src=" :active = isExactActive ? pic_active.png : pic_inactive.png}}" /> //Something along these lines ...

Encountering the error message "AngularJS error: $(...).modal is not a function" after updating from Bootstrap 3.3.6 to version 4.0

Since updating the bootstrap version in my application from 3.3.6 to 4, I've been encountering an error stating that $(...).modal is not a function. This was previously working fine before the update. angular.js:14700 TypeError: $(...).modal is n ...

Applying CSS onmousemove does not function properly in conjunction with Bootstrap framework

Currently, I have a code snippet that enables an absolutely positioned box to follow the movement of the mouse cursor: $(document).mousemove( function(e) { $(".wordbox").css({ top: "calc(" + e.pageY + "px - 0.8em)", left: e.pageX }) ...

AngularJS chatbox widget for interactive communication

Currently, I am in the process of developing the back-end for a web application utilizing angularJS. One of the key features is allowing users to communicate with each other through a pop-up chat box similar to those found in Gmail or Facebook. My goal is ...

Issue with Internet Explorer 7: Floating elements are incorrectly positioned below their intended placement

Upon visiting using IE7, you may notice that the two middle columns are being pushed down to the bottom of the page. I have attempted to resolve this issue by applying display:inline to both columns without success. Any assistance on this matter would be ...

Using CSS to disable an image map in conjunction with dynamically adjusting CSS styling

On the desktop version of the website, there is an imagemap implemented. However, when the site transitions into tablet or mobile view, the imagemap should be disabled to allow for a simpler navigation area to be displayed. I attempted to use the following ...

particular shade for button border and background

I'm looking to create a button using Material UI that has a specific design. Right now, I've only been able to achieve this: https://i.stack.imgur.com/xvv7s.png Here is the code I am currently using. If anyone can help me identify what I'm ...

A guide to filling an irregular shape (such as a star) based on a percentage using CSS in a React project

I am currently working on developing a React component that showcases a rating percentage using a star icon with two different shades. For example, if the input rating is 79%, I want to display a star with 79% of it in gold color and the remaining 21% in ...

The hover function stops working once the dropdown class has been removed

I am currently experimenting with a bootstrap template. In the navigation bar, there is an option for "Blog" and "Test". For the "Test" button, I decided to remove the li class="dropdown " because I wanted to create a button that changes color on hover si ...

Creating dynamic CSS classes with SCSS/SASS

Recently, I encountered a scenario where I needed to automate the creation of a series of CSS classes by utilizing a mixin. This led me to ponder if there is a dynamic approach to achieve this. Essentially, the classes I have are structured as follows: . ...

Tips for aligning a radio button and label on the same line without breaking the layout in HTML and CSS

I'm encountering a problem with positioning an HTML radio button alongside its label. When the label text is too lengthy, it ends up wrapping below the radio button instead of staying on the same line. Here is the html: <div class="form-check ...

Is it possible for a Bootstrap modal dialog to overlay another dialog window?

<button class="btn" onClick="$('#firstModal').modal('show');">Click Here</button> <!-- Modal --> <div id="firstModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden=" ...

Several problems with CSS regarding DIV height set to 100% and the content inside

I'm facing a bit of a puzzle here. I have a div that spans the full height of the browser, with a background set to 100% size and image content contained in two inline divs that are vertically aligned in the middle. In one of these divs, the image is ...