Steps on creating a two-column layout with a responsive breakpoint

I want to design a div that includes two texts. The initial text should be placed in the first column and expand into the second column if it's lengthy. The second text should be positioned above the expanded text from the first column.

Here is an example of what I am aiming for:

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

Can someone guide me on how to achieve this using HTML and CSS?

Answer №1

If you want to move text to the next column, consider experimenting with CSS properties like float and clear.

Here's an example that demonstrates pushing a title to the next column using a CSS variable to redefine the height of the clearer.

// You can turn this code snippet into a function that triggers on page load or resize
var getIt = document.getElementById("test1");
var thisTall = getIt.offsetHeight + "px";
getIt.style.setProperty("--hgt", thisTall);
div {
  column-count: 2;
  border: solid;
  column-fill: balance;
}

div::before {
  content: '.';
  float: left;
  min-height: var(--hgt);
  width: 3px;
  background: red;
}

h2, p::first-line {
  clear: both;
  color: red;
  float: left;
  width: 100%;
  margin-top: 0;
  text-align: center;
}

p {text-align:justify}
<div id="test1">
  <h2>Title sent to next column</h2>
  <p>!! the script is not fired on resize !! <br> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas...</p>

</div>

Visit Codepen to experiment further.

The introductory text is positioned at the top for easier alignment with floating elements.

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

Multer returns an undefined response

I am currently utilizing multer in my Node.js application to handle file uploads, along with AngularJS for the front end. However, when I click on the upload image button, I'm getting an undefined response in the console. Can someone assist me in reso ...

Is there a way to repurpose a displayed.bs.collapse function for multiple uses?

I have implemented a JavaScript snippet that enables a collapse feature with color and chevron changes based on its open or closed state. Now, I am attempting to replicate this functionality for a different button but haven't had success by changing t ...

Tips for adjusting an svg component to suit various screen sizes

I inserted the following SVG component into my HTML file. It fits perfectly on my tablet, but it's too large for my smartphone. How can we automatically adjust the size of the SVG to fit different screens? <svg viewBox="310 -25 380 450" w ...

Tips on choosing the initial N website elements that match a specific CSS selector using Python Selenium

Currently, I am utilizing phantomJS in a python/selenium configuration to scrape the screen. My main objective is to extract the first N elements that match a specified CSS selector. An issue I am encountering is that there are significantly more matching ...

Retrieve information and auto-fill text boxes based on the selected dropdown menu option

UPDATED QUESTION STATUS I'm currently working with Laravel 5.7 and VueJs 2.5.*. However, I am facing a challenge where I need to automatically populate form textboxes with data from the database when a dropdown option is selected. Despite my efforts ...

It is proving challenging to fully eliminate top and bottom padding in MUI TableCell in order to enable clickable whole cell content

I've been working on making the content of my table cells clickable for routing within my app, and I've made some progress in removing unclickable horizontal space by adjusting padding. However, I'm still facing issues with unclickable space ...

fixed footer with fixed height on parent container

I have successfully implemented a sticky footer on my web pages by following specific instructions. http://css-tricks.com/snippets/css/sticky-footer/ The recommended approach includes using min-height:100% and not specifying the height property. .page-w ...

Is there a way to transform individual data into a collective group dataset?

Here is the input data provided: data = [ { name: "John Cena", groupName: "WWE" }, { name: "Nandini", groupName: null }, { name: "Rock", groupName: "WWE" }, { name: "Vinay", groupName: null }, { name: "Rey Mesterio", groupName: "WWE" ...

A technique for combining the elements of one array in a loop and then transferring them to another array before adding them to an object

In order to streamline the process of calculating tip percentages based on bill amounts, I have developed a method within the object itself. However, to prevent redundancy, I have also created a separate function called calculateTip and a dedicated for loo ...

What is the best way to prompt users to log in with a modal popup if they are not authenticated yet?

My current view showcases a table of data: @if(Request.IsAuthenticated){ <fieldset id="detailPrix"> <legend>Details prix</legend> <div class="scrollableContainer"> <div class="scrollingArea"& ...

What is the best way to extract the text "TSV SCHOTT Mainz" from HTML using Python?

https://i.sstatic.net/2KDgz.png Hello, I'm struggling to locate the text "TSV SCHOTT Mainz" in the HTML code because I am unsure of which part to target. I have attempted the following: import requests from bs4 import BeautifulSoup # URL of the Bo ...

AngularJS filtering with multiple conditions

My ng-repeat list is currently displaying a collection of objects with a filter applied to only show objects inserted today. Here is how it looks: <div class="row msf-row" ng-repeat="record in recordlist | filter: record.date = dateJson"> Whi ...

Sending information back to the server without causing a postback, all while remaining unseen

I have a straightforward JavaScript function on my ASP.NET page that writes data to a hidden field. However, in order to retrieve this data the form needs to be submitted back to the server. The issue is that submitting the form causes the page to reload ...

Step-by-step guide on downloading an image in HTML with the click of a button

I have a photo gallery on my website created using PHP and HTML. I am looking to add a functionality where users can click on a button to download the image that is currently set as a background of a specific div element in the gallery. The download button ...

Efficiently and consistently refreshing the DOM with information while maintaining page integrity

I'm currently developing a Single Page Application (SPA) that utilizes AJAX to dynamically load content into a specific div. The layout consists of a side accordion menu, where clicking on an item loads relevant information in a neighboring div. Howev ...

Guide to surrounding each letter in a user-entered string with div elements

I am currently working on a small web app that allows users to input text. The goal is to have the app parse EACH LETTER entered by the user, creating a new div for each character (even spaces). Although the code is functional, I am facing an issue with s ...

Guide to incorporating eslint with Next.js in a project that already has an eslint configuration

I recently created a new next.js project within my existing Node.js project, which already has an eslint config set up. Here's how the folder structure looks now: ...

Retrieving data from a cell within an HTML table by utilizing the children[] method

I've been trying to extract a specific value from the HTML of a cell in an HTML table. I attempted to use the .rows parameter initially, but that resulted in the JavaScript halting at the line involving .row. Currently, I have resorted to assigning an ...

Unable to retrieve data from Meteor find query

I have a collection created in collections.js portfolioItems = new Mongo.Collection('portfolioitems'); This collection is then subscribed to in subscriptions.js Meteor.subscribe('portfolioitems'); And published in publications.js M ...

Comparing `$('p:first');` with `document.querySelector('p');`

I am confused. $("p:first") chooses the initial p element. It is similar to document.querySelector("p"); Why do we need to use both methods? Apologies if this question seems silly, but I want to fully understand. UPDATE In what scen ...