I have a form laid out using display: table-row and table-cell, where each row contains two cells: a label and an input. Both cells have an unspecified width, because I want them to stretch along with the contents inside them.
However, in a particular cell I need to add an element with extra information. No matter how long the information in it is, I don't want it to stretch the right-hand cell. I just want the text to wrap as if the block had a width set, but without setting one (because I do not know what it will have to be)
.row {
display: table-row;
outline: 1px solid black;
}
.cell {
display: table-cell;
padding: 5px;
}
.info {
display: block;
}
<div class="row">
<div class="cell">Label</div>
<div class="cell input">
<input type="text" />
</div>
</div>
<div class="row">
<div class="cell">Another label</div>
<div class="cell input">
<input type="text" />
<span class="info">This text should not make the cell larger</span>
</div>
</div>
I know that the relatively new width: min-content should be able to handle this, which it does on inline blocks but that defies the purpose of using table-cell, which I found out during my previous questionx. Also it's not supported by IE, which I do need.
I've tried setting the .info to inline and inline-block on a new line (both using <br> and a pseudo-element with display: block), all in combination with word-break: break-word but to no avail.
Strangely, when I apply max-width: 0 to the .input div after the page rendered (using the developer tools) the cell will shrink to fit the input, and it produces exactly the desired effect. However, setting this value beforehand will actually force a 0 width cell and all the contents will overflow.
I really don't want to resort to having to set this value after rendering using javascript. Is there a CSS way to do this?
