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

后端 未结 3 657
北海茫月
北海茫月 2021-01-20 15:56

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

相关标签:
3条回答
  • 2021-01-20 16:25

    There are som jquery plugins. For example: Columnizer

    0 讨论(0)
  • 2021-01-20 16:34

    you think something like this?

    var yourText = $('selector');
    $(yourText).each(function() {
        if ($(this).text().length >= 200) {
            $(this).text($(this).text().substring(0, 200)0);
        }
    });
    

    It wiil get the first 200 letters.. for the next 200 you need to switch the variables 0,200 to 200, 400 unfortunately it will split a word and does not recognize that some letters are wider than others...

    0 讨论(0)
  • 2021-01-20 16:38

    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.

    0 讨论(0)
提交回复
热议问题