Move content to a separate block without using JavaScript to handle overflow

In trying to achieve what I have in mind here, it may be a challenge, but I'm putting it out there to see if anyone else might have a creative solution that eludes me.

My goal is to replicate the design of a government form. Essentially, I want to create a "continued" section where text that doesn't fit on the first page spills over onto the second page seamlessly.

Below is an example code snippet that accomplishes this using JavaScript. However, our rendering engine for HTML does not support JavaScript, especially for print layouts.

document.getElementById("content2").scrollTop = 150;
#content1, #content2{
      overflow: hidden;
      width: 250px;
      height: 150px;
      border: 1px solid black;
      padding: 5px;
  }
  #content2::after{
      /* 
       * This is a spacer to ensure we can scroll to a value that has no content if the 
       * overflowed content does not fill box 2
       */
      content: " ";
      display: block;
      height: 150px;
  }
<h1>Split up content</h1>
  <h2>Here's the first box</h2>
  <div id="content1">
      <p>
          This is some really long content.
      </p>
      <p>
          My goal is for it to start in the first content block until the overflow is reached, 
          and then the overflowed content will automatically be displayed in the second box.
      </p>
      <p>
          This is intended for use in a print layout, so I cannot rely on JavaScript.
      </p>
  </div>
  <h2>And here's the second</h2>
  <div id="content2">
      <p>
          This is some really long content.
      </p>
      <p>
          My goal is for it to start in the first content block until the overflow is reached, 
          and then the overflowed content will automatically be displayed in the second box.
      </p>
      <p>
          This is intended for use in a print layout, so I cannot rely on JavaScript.
      </p>
  </div>

Is there a way to achieve the same result without using JavaScript? Another idea I had was to try splitting the content before inserting it into our HTML template, but predicting the break point accurately seems challenging without actual text layout.

Answer №1

After much trial and error, I devised a solution using floats that, while a bit cumbersome, gets the job done effectively. By utilizing psuedo-elements as invisible spacer floats, we can then insert the "interrupting" content as a float with a width of 100%.

*{
    box-sizing: border-box;
}
body{
    width: 250px;
}
h2{
    width: 100%;
    border: 1px solid black;
    margin: 0;
}
#title1{
    border-bottom: none;
}
#title1::after{
    /* This additional element sets the height of the first block */
    display: block;
    content: " ";
    width: 0;
    height: 150px;
    float: left;
}
#title2{
    /* This follows below the pseudo-element, disrupting the content flow */
    float: left;
    clear: left;
}
#content{
    border: 1px solid black;
}
<h1>Divide Content</h1>
  <h2 id="title1">First Box Here</h2>
  <h2 id="title2">Second Box Below</h2>
  <div id="content">
      <p>
          This constitutes some lengthy text.
      </p>
      <p>
          The aim is for it to occupy the initial content block until overflow occurs, 
          at which point the excess content will smoothly transition into the second box.
      </p>
      <p>
          This functionality is intended for print layout use, hence JavaScript cannot be relied upon.
      </p>
  </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

Ways to create spacing between property columns in MUI grid fashion

Is there a way to achieve space-between alignment when elements are stacked vertically in MUI Grid instead of using flex? I've come across suggestions involving giving flex:1 and height:100%, but I'm specifically interested in achieving this with ...

Navigating through pages: How can I retrieve the current page value for implementing next and previous functions in Angular 7?

Greetings, I am a new learner of Angular and currently working on custom pagination. However, I am facing difficulty in finding the current page for implementing the next and previous functions. Can anyone guide me on how to obtain the current page value? ...

Trouble with canvas setLineDash and lineDashOffset persisting in iOS/Safari?

Check out the fiddle linked here: http://jsfiddle.net/mYdm9/4/ When I execute the following code on my PC: ctx.lineWidth=20; ctx.setLineDash([20,30]); ctx.lineDashOffset=10; ctx.beginPath(); ctx.moveTo(150,150); ctx.lineTo(240,240); ctx.lineTo(180,40); ...

The user can witness the appearance of a scrollbar when utilizing the

Struggling to remove the scroll bar from my ion-scroll. Have tried various methods but nothing seems to work. Need assistance with this, please! Attempted using all attributes and even used CSS like ::-webkit-scrollbar with display: none;, which hides it ...

Challenges associated with Bootstrap toggle switch

I am having some difficulties with using bootstrap switch. I have tried the examples provided on , but regardless of the classes I apply, the buttons remain the same small size and the text for ON and OFF is barely visible. I can't seem to figure out ...

"Exploring the Possibilities of iOS Webview with jFontSize

Trying to use jFontSize on a local html page displayed in a WebView, allowing users to change text size. However, adding breaks the script's functionality. Even with another script, the issue persists. HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD ...

The alignment of inline-block elements is not being maintained on the same line

Here's a question I have about my embedded form. Why does the display property of inline-block make the "submit" and "terms" elements appear higher than the email field? And more importantly, how can I fix this issue? I've attempted to use the t ...

Guide on marking and unmarking all checkbox options within a specified div

I need a script that will uncheck all checkboxes within the 'test' div except for those that have the disabled attribute. <div id="test"> <input type="checkbox" id="check1" name="check1"> <input type="checkbox" id="check01" ...

What is the reason behind the immediate firing of the animate callback function when a CSS transition is present?

I am facing an issue where the callback function fires immediately, disregarding the linear ease type and defaulting to the swing ease in CSS transitions. Is there a way to ensure that the animate function works correctly with the transition? The reason fo ...

Could someone offer some assistance in grasping the order of operations in jQuery syntax

Until now, my approach has been deciphering and analyzing various codes and techniques for effectively utilizing jQuery, but I often find myself overwhelmed by the choices presented. This often leads to unnecessary complexity in my code. What I aim to ach ...

Create an HTML button on the homepage that directs users to the "about" page

I've been struggling to make a button in my Ionic app navigate to a different page upon clicking. Despite being new to Ionic, I've spent hours trying to solve this issue. Below is the HTML code in home.page.html: <ion-header> &l ...

Is it possible to modify the dirpagination filter in AngularJS from an input box to a select box?

I have been experimenting with the AngularJS dirpagination library. Feel free to check it out at this link. You can also see a code demo at: this link. My question is, is it possible to change the input box to a select box and still have the same functio ...

Adding a stylish underline to text using HTML and CSS

Looking for some assistance with my Html and CSS website project. I am currently facing a challenge trying to place a border below the text as shown in the provided image. Below is the snippet of my Html code: <div class="Sectionheading"> ...

Setting a const value (true or false) based on the size of the window - a step-by-step guide

While studying, I encountered a challenge: In the code below, I need to dynamically set useState(false) based on the screen size. If the screen is larger than 947px, for instance, it should automatically be changed to true. The issue arises because sett ...

Tips for Validating Radio Buttons in Angular Reactive Forms and Displaying Error Messages upon Submission

Objective: Ensure that the radio buttons are mandatory. Challenge: The element mat-error and its content are being displayed immediately, even before the form is submitted. It should only show up when the user tries to submit the form. I attempted to use ...

Guide to displaying a template using Vue.js

Incorporating jQuery and vuejs version 2.3.4: https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js The code snippet below demonstrates my current setup: // Instantiating Vue. vueVar = new Vue({ el: '#content', ...

Is there a way to turn off two finger scrolling on a Macbook using JavaScript?

Hey there! I'm facing a little dilemma. I've got this div container that's 300px wide, positioned relative, and has an overflow hidden property. Inside it, there are two child divs with absolute position. I'm using CSS3 to translate the ...

Querying data based on date range in PHP

Hello, I encountered an issue with the between operator in MySQL PHP as the output seems to be incorrect. $currentdate = "05-23-2016"; $startdate = "01-01-1001"; $sql="SELECT * FROM `trial` WHERE Schedule BETWEEN '".$startdate."' AND '". ...

Scheduling with FullCalendar: Embracing the Unique Parallelogram Events

Is there a way to change the shape of the event from a square to a parallelogram? Here is an example in the image below: https://i.sstatic.net/hKtz7.png I attempted to modify the CSS with the code snippet below: .fc-event-container{ background-colo ...

Creating a calculator with JQuery and encountering challenges with performing multiple calculations

I've been working on a calculator using jQuery, but I'm encountering issues with the clear button not functioning properly after multiple calculations. On top of that, subsequent calculations are producing inaccurate results. I am seeking to enh ...