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
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()
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.