How to flow text between multiple containers in HTML [duplicate]

20 hours ago 1
ARTICLE AD BOX

CSS Regions (still a 'draft', but) is aiming to fix this problem:

The CSS regions module allows content to flow across multiple areas called regions. The regions are not necessarily contiguous in the document order. The CSS regions module provides an advanced content flow mechanism, which can be combined with positioning schemes as defined by other CSS modules such as the Multi-Column Module [CSS3COL] or the Grid Layout Module [CSS3-GRID-LAYOUT] to position the regions where content flows.

More info and tutorials at https://www.adobe.com/devnet/archive/html5/articles/css3-regions.html

answered Sep 1, 2013 at 11:52

haim770's user avatar

2 Comments

"Current Chrome status: No longer pursuing" :-(

2015-04-29T23:41:51.537Z+00:00

Adobe.com as a source? Hm... Anyway, the link is broken. And the feature development has ceased.

2026-02-03T17:10:08.727Z+00:00

Here is one for fixed-width approach. The gap between two columns will equal to width of main div.

Fiddle

<div class="container"> <div class="sides">The big text here.<div> <div class="main"></div> </div>

For variable width you need JS or jQuery.

Update:

I have used jQuery for this purpose as I have found pure JS difficult to find solution of this.

function setGap() { var width = $(".main").width(); $(".sides").css({ "-moz-column-gap": width + "px", "-webkit-column-gap": width + "px", "column-gap": width + "px" }); } $(window).resize(setGap); setGap();

Fiddle

Update 1:

function setGap() { var width = document.getElementsByClassName("main")[0].offsetWidth; var elem = document.getElementsByClassName("sides")[0]; var style = elem.getAttribute("style"); if (typeof style != "null") { style = "-moz-column-gap:" + width + "px; -webkit-column-gap:" + width + "px; column-gap:" + width + "px"; elem.setAttribute("style", style); } else { style += "-moz-column-gap:" + width + "px; -webkit-column-gap:" + width + "px; column-gap:" + width + "px"; elem.setAttribute("style", style); } } window.onresize = setGap; setGap();

Fiddle

answered Sep 1, 2013 at 11:32

Talha Akbar's user avatar

6 Comments

Still this is a workaround using one DIV , but a nice one

2013-09-01T11:36:35.037Z+00:00

The OP said explicitly without libraries :)

2013-09-01T11:41:00.697Z+00:00

@RokoC.Buljan Well, I am just suggesting him my opinion. Yeah, I am trying to reproduce it in pure JS.

2013-09-01T11:43:20.6Z+00:00

@RokoC.Buljan Found pure JS solution :P

2013-09-01T12:01:35.32Z+00:00

Nice, but still, it's not using 2 separate DIVs :)

2013-09-01T12:07:31.353Z+00:00

so far (2012) It's not possible using CSS, CSS3 (with 2 separate elements)

but using JS You can clone the content and use scrollTop on the right element :

LIVE DEMO

var d = document, $left = d.getElementById('left'), $right = d.getElementById('right'), leftH = $left.offsetHeight; $right.innerHTML = $left.innerHTML +'<p style="height:'+ leftH +'px;" />'; $right.scrollTop = leftH;

As you can see I'm appending also an empty paragraph, to fix the right element need to scrollTop some amount of px

Note: add overflow:hidden; to your ID elements #left and #right

answered Sep 1, 2013 at 11:46

Roko C. Buljan's user avatar

5 Comments

Good :) better than mine.

2013-09-01T11:50:09.387Z+00:00

@MuhammadTalhaAkbar I was inspired by David's comment but found a simpler solution ;)

2013-09-01T11:50:40.663Z+00:00

@jeff than the OP should not build that way web sites :)

2013-09-01T12:46:41.72Z+00:00

This cuts the text off through the middle of the line, so the top half of several characters are in one div, and the bottom half are in another. Individual characters are cut in half. That's not a good solution at all.

2016-09-17T16:40:44.163Z+00:00

@iconoclast at least the right characters are cut-off. It's on you to figure out a better solution or simply set the right font size and line-height. This is just to give you an idea.

2016-09-18T03:30:24.863Z+00:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Read Entire Article