table-cell - some kind of colspan?

前端 未结 8 1818
甜味超标
甜味超标 2020-12-06 09:46

I am a bit puzzled right now, because I had CSS code that worked, but it wasn\'t beautiful at all. I now want to rework this CSS styles and build them via LESS. And I have b

相关标签:
8条回答
  • 2020-12-06 10:34

    I found a solution using jquery and table-layout: fixed. Here is my fiddle: http://jsfiddle.net/emilianolch/5nvxv5ko/

    HTML:

    <div class="table">
        <div class="table-row">
            <div class="table-cell">
                top left cell
            </div>
            <div class="table-cell">
                top right cell
            </div>
        </div>
        <div class="table-row">
            <div class="table-cell colspan">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
            </div>
        </div>
        <div class="table-row">
            <div class="table-cell">
                bottom left cell
            </div>
            <div class="table-cell">
                bottom right cell
            </div>
        </div>
    </div>
    

    CSS:

    .table {
        display: table;
        table-layout: fixed;
        width: 100%;
        border-collapse: collapse;
    }
    
    .table-row {
        display: table-row;
        border-collapse: collapse;
    }
    
    .table-cell {
        display: table-cell;
        padding: 5px;
        border: 1px solid black;
    }
    
    .table-cell.colspan {
        display: none;
        /* collapse border */
        margin-top: -1px;
        margin-bottom: -1px;
    }
    

    JS:

    var rowWidth = $('.table-row:first').width();
    var colWidth = $('.table-cell:first').width();
    var marginRight = colWidth - rowWidth + 11;
    $('.table-cell.colspan').css('margin-right', marginRight + 'px').show()
    
    0 讨论(0)
  • 2020-12-06 10:37

    CSS has no colspan analog. Based on your example, you can just mark up your last row as a separate nontably block.

    You could also use display: table-caption in conjunction with caption-side: bottom to display the table row as a last “row” that spans all columns. See live demo.

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