balanced alternating column layout in CSS3

前端 未结 6 1704
无人共我
无人共我 2021-02-08 04:32

I\'m trying create a balanced (2-) column-layout.

The content is not text but blocks and varies in height. The content should be placed alternatingly left and right, as

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-08 04:48

    I would say this is not possible without JS. Here is a fiddle I made based on an article from Ben Holland. At least to me looks like what you are after.

    http://jsfiddle.net/QWsBJ/2/

    HTML:

    
      

    ***Content***

    ***Content***

    ***Content***

    ***Content***

    ***Content***

    CSS:

    .block {
      position: absolute;
      background: #eee;
      padding: 20px;
      width: 300px;
      border: 1px solid #ffffd;
    }
    

    JS:

    var colCount = 0;
    var colWidth = 0;
    var margin = 20;
    var blocks = [];
    
    $(function(){
        $(window).resize(setupBlocks);
    });
    
    function setupBlocks() {
        colWidth = $('.block').outerWidth();
        colCount = 2
        for(var i=0;i

提交回复
热议问题