jQuery.
HTML:
<div class="table">
<div class="left">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="right">Lorem Ipsum</div>
</div>
CSS , max-width: 0 ( table):
.table {
display: table;
width: 100%;
}
.left, .right {
display: table-cell;
padding: 0 5px 0 5px;
max-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
, div, 50% div, - . , , ,, , , . .
$.fn.textWidth = function(text, font) {
if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
$.fn.textWidth.fakeEl.text(text || this.val() || this.text()).css('font', font || this.css('font'));
return $.fn.textWidth.fakeEl.width();
};
$('.right').on('input', function() {
var $width = $(this).textWidth();
$width += 10;
$(this).width($width);
}).trigger('input');
, , padding; . fiddle.
To use this in a multi-row table, you can change the jQuery iteration over the cells in the column and set the column width to the desired width of the widest cell in the column. Or, if you know which one is the widest (as you think, from your violin), you can just direct jQuery to get the width of it.
source
share