0

Note: This is an alternate planned approach to this question: Multiple column articles in Joomla

I've got a client who wants a multi column layout, which should be generated automatically from a non-column HTML block.

What is the feasibility of using JavaScript (and jQuery) to create a multi-column system from a single block of HTML? And if it is possible how would I go about doing it?

Thanks.

2 Answers 2

1

This is just an example how you can solve your problem. Of cause this solution can be refined.

function textSplitter(){
}

textSplitter.prototype.LENGTH_TO_SPLIT=5000 //max chars in single line

textSplitter.prototype.split=function(id){
    var contentDiv=document.getElementById(id); // get an element
    var text=contentDiv.innerHTML; 
    var length= text.length; 
    if(length){
        var div1sbstr=text.substring(0,this.LENGTH_TO_SPLIT); //take a substring
        var div1=document.createElement("div");
        contentDiv.appendChild(div1); // append it
    }
    if(length>this.LENGTH_TO_SPLIT){
        var div2sbstr=text.substring(this.LENGTH_TO_SPLIT,this.LENGTH_TO_SPLIT*2);
        var div2=document.createElement("div");
        contentDiv.appendChild(div2);
    }
    if(length>this.LENGTH_TO_SPLIT*2){
        var div3sbstr=text.substring(this.LENGTH_TO_SPLIT*2,this.LENGTH_TO_SPLIT*3);
        var div3=document.createElement("div");
        contentDiv.appendChild(div3);
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

As the goal is some approxiamately equal height columns (I suppose), wouldn't it be more intelligent to calcute the heights of the containing <p> or <div> elements? Is this possible?
Yes it is possible i suppose. Of cause you can refine solution - this is just a hitn on how to start.
1

You could use an unordered list with negative margins.

<ul>
   <li class="col1">Eggs</li>
   <li class="col1">Ham<li>
   <li class="col2 top">Bread<li>
   <li class="col2">Butter<li>
   <li class="col3 top">Flour<li>
   <li class="col3">Cream</li>
</ul>

ul {list-style:none;}
li {line-height:1.3em;}
.col2 {margin-left:100px;}
.col3 {margin-left:200px;}
.top {margin-top:-2.6em;} /* the clincher */

All code taken from Smashing Magazine - The Definitive Guide to Using Negative Margins.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.