Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to divide text into columns, if I get text dynamically for database using Javascript and CSS?

I think a script makes a certain number of characters in each container can work. Do you know any script like that? It is a responsive design I can use several css files but I need only one html file:

the problem is in text which I'll get dynamically so I have no idea how many characters I'll get. In desktop size the paragraphs are arranged one above the others. In Ipad size the paragraphs are arranged into two columns, some on right side and some on the left.

like image 312
sara f Avatar asked Jul 20 '26 00:07

sara f


2 Answers

You can use CSS3's columns to achieve that task with CSS alone, though it is not supported in IE8 and below;

div {
    -moz-column-count: 3;
    -moz-column-gap: 10px;
    -webkit-column-count: 3;
    -webkit-column-gap: 10px;
    column-count: 3;
    column-gap: 10px;
    width: 560px;
}

As a fallback for IE you can use conditional comments and something like jQuery Masonry or Columnizer as suggested by other posters.

Demo that gracefully degrades in IE.

like image 194
Andres Ilich Avatar answered Jul 22 '26 15:07

Andres Ilich


There are som jquery plugins. For example: Columnizer

like image 34
Paul Lernmark Avatar answered Jul 22 '26 13:07

Paul Lernmark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!