JSFiddle - React, Tailwind, and code Playground
by scooterlord
HTML
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<div class="table">
<div class="cell">
Content 1
</div>
<div class="cell">
<div class="table">
<div class="cell">
Content 1
</div>
<div class="cell">
Cont
</div>
<div class="cell">
Content 3
</div>
</div>
</div>
<div class="cell">
Content 3Content 3Content 3
</div>
</div>
CSS
.table {
display: table;
border: 1px solid #e4e5e7;
white-space: nowrap;
}
.cell {
display: table-cell;
vertical-align: middle;
padding: 10px;
border: 1px solid #e4e5e7;
}
.cell .table {
margin-bottom: -2px;
}
.table.wrap {
white-space: normal;
}
.table.wrap > .cell {
display: block;
}
JavaScript
$('.table').each(function(i) {
tw = 0;
$(this).children('.cell').each(function() {
tw += $(this).outerWidth(true);
});
$(this).attr('data-width', tw);
});
$(window).on('resize', function() {
w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
$('.table').each(function(i) {
if ($(this).width() >= w) {
$(this).addClass('wrap');
} else if (w >= $(this).attr('data-width')) {
$(this).removeClass('wrap');
}
});
}).resize();