Organizing semantic elements at the beginning of a column

I am facing a challenge with formatting a long text into 2 columns while also including a fixed height table in one of the columns.

The goal is to have the table at the top of the 2nd column without splitting the text or using JavaScript.

The table should be one column wide and maintain a fixed height, with the text flowing around it if possible.

I have tried various CSS techniques such as floating the table to the right within a column-count: 2 element, but the results were not as desired.

Other attempts, like using CSS grid or absolute positioning, did not yield the desired outcome without causing overlap issues.

I am looking for a pure CSS solution that will allow the text to wrap around the table in a way that resembles the desired result shown in the link below.

Any insights or suggestions on achieving this layout using CSS only would be greatly appreciated.

Note: The final HTML will be converted to a PDF using PrinceXML.

Answer №1

UPDATE: encountered an issue in Chrome, but resolved it by adding transform: translateZ(0); (may trigger a repaint of the first paragraph or cause some layout shifts in Chrome)


While technically achievable, the method relies on the special element having a fixed height (which is not always practical or realistic). You have control over how it appears on the screen, but there are some limitations.

➡️ Check out the Codepen demo

The solution involves:

  • Using absolute positioning for the special element with a fixed height
  • Applying a top padding to the container to prevent overlap with other elements, creating space above the first column
  • Adding a negative margin to the first paragraph to fill the space in the first column

The use of CSS3 columns ensures the overall height is maintained properly.

/* CSS styles */
/* Adjust the fixed height value (10rem) of the special element as needed */
.col-2 {
  position: relative;
  columns: 2;
  width: 40rem;
  padding: 11rem 1rem 1rem 1rem;
  background-color: lightyellow;
}

.col-2 p:first-of-type {
  margin-top: -10rem;
  background-color: lightblue;
  transform: translateZ(0); /* Chrome bugfix for paragraph disappearing */
}

.col-2 aside {
  position: absolute;
  top: 1rem;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 50%;
  height: 9rem; /* Leaves 1rem margin below */
  font-weight: bold;
  font-size: 1.5rem;
  background-color: tomato;
}

.col-2 + * {
  max-width: 60rem;
  min-height: 20rem;
  padding: 1rem;
  background-color: #f5f5f5;
}
<!-- Demo cases: Scroll for 2 test cases -->
<h1>2 test cases in this pen (scroll)</h1>
<div class="col-2">
  <p>Case 1: Special element at the end of container.<br>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil vitae a voluptatibus quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
  <p>Additional paragraphs...</p>
  <aside>your element</aside>
</div>

<p>Remaining content...</p>

<div class="col-2">
  <aside>your element</aside>
  <p>Case 2: Special element at the beginning of its container.<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
  <p>Additional paragraphs...</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

How can I construct a frame-like structure using PHP and HTML?

Looking to create a page with a two-frame structure. The left frame will always display a small form with 10 entries that, upon submission, trigger some processing and display results. The left frame must remain accessible at all times, while the right fra ...

navigate through laravel pagination to different pages

Is there a way to navigate to a particular page on the pagination? ...

Issue with interaction between php and jQuery on click event

I had been facing a challenge with this issue (after checking this site) where I discovered that I forgot to use .on to delegate a click function that should be triggered when clicking on a piece of dynamically generated HTML in PHP. I have now included t ...

Exploring design techniques in React Native

I am currently part of a team working on a react native project with multiple contributors. My goal is to find an effective way to segregate the styling tasks from coding, allowing UI developers to work independently without relying on code developers. In ...

What is the best way to update a targeted component in React when triggered by an event handler?

Your goal may seem straightforward, but getting a reference to a specific component using this is proving to be tricky. Here we have our App.js file: import React, { Component } from 'react'; import CoolBox from './coolBox.js'; import ...

What sets apart the HTML tags for embed, object, and video elements?

Can you explain the technical distinctions among these three tags and provide reasons why one might be chosen over another? Additionally, why did the embed tag lose popularity in HTML 4 and get replaced by object, only to see a resurgence in HTML 5 while ...

The md-autocomplete feature showcases search results in a list format rather than a dropdown menu

Currently, I am working on implementing the Angular Material md-autocomplete tag to provide suggestions for zip codes in a form. To achieve this, I have set up an asynchronous service that fetches the suggestions and populates the results. My reference poi ...

Finding the current HTML page URL in Ionic 2: A step-by-step guide

Can the URL of the current HTML page be obtained and then converted to PDF using the cordova-pdf-generator package? ...

Is there a way to obtain the coordinates of an SVG element by simply clicking on a specific point?

I'm still learning about SVG and I'm trying to trigger an event that captures the click coordinates when clicking on the SVG. I have a few questions: Since I'm using Angular, I'm unsure if it's possible to keep my function in th ...

Expanding the padding of the selected item to create more breathing room

Upon examining the following: https://jsfiddle.net/h8kmove5/27/ Let's say you select 9 at the bottom. The display shows 8 9 10. My intention is to create some additional space on either side of 9, or any other active item for that matter. This way, ...

Arranging Data in an HTML Table Using TableSorter

I have been trying to incorporate sortable columns into my HTML table and decided to experiment with the jquery tablesorter. I have followed the syntax below, but for some reason, my table is not allowing me to sort. Can you help me understand why? &l ...

Steps for including a solid bottom border in a toggled navigation bar that is responsive

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document&l ...

What is the best way to display the entire background image in a jumbotron?

After some experimentation, I discovered that by increasing the amount of content I have, it displays the full background image. Is there a clean and efficient way to achieve this? <div class="jumbotron jumbotron-fluid" style="background: url('./a ...

Guide on utilizing every array value during each iteration of a for loop, ensuring that the same number of values

Below is the equipos_seleccionados array: ["12 - v4", "100 - v500"] This is a preview of the frontend: https://i.sstatic.net/nJU9d.png When you input values in the head section, textboxes are generated automatically. Objective: Assi ...

Angular HTML fails to update correctly after changes in input data occur

Within my angular application, there is an asset creator component designed for creating, displaying, and editing THREE.js 3D models. The goal was to implement a tree-view list to showcase the nested groups of meshes that constitute the selected model, alo ...

Adjust the font color of the progress bar dynamically based on the background color using SCSS and HTML

I am currently working on a progress bar that displays the percentage of delivery completed. While I have successfully designed the progress bar itself, I am struggling to change the text font color based on the background color of the bar. <div class=& ...

Storing the entire HTML5 game on the local device for faster loading and

I'm in the process of developing a 2D HTML5 game and I'm looking to optimize asset storage by requesting each asset only once and then storing them in the user's filesystem. Currently, I'm utilizing localStorage for this purpose, but it ...

Struggle with Arranging Elements in CSS using position absolute & relative

Currently tackling a project involving adjusting the positioning of elements within a sidebar. The sidebar holds Font Awesome icons and corresponding text elements, with the goal of moving both the icons and text together as one unit using attribute and cl ...

Tips for utilizing state and city dropdown menus in JavaScript multiple times without interfering with other dropdowns

Currently, I am utilizing CodeIgniter to create a dynamic dropdown functionality. The setup involves four select country dropdowns where the state options will populate based on the selected country, and once a state is chosen, the corresponding city optio ...

Which names can be used for HTML form tags in jQuery?

Recently, I encountered an issue related to jQuery form serialization which stemmed from naming a form tag "elements". The problem arose when using jQuery $(’form’).serialize(). Here is an example of the problematic code: <form> <input name=" ...