Preconditions: I am limited to old browsers (around Chrome 25), which do not support a lot of CSS features. Also, the table structure with 3 columns needs to remain, and the first column should not take more space, than it needs.
Goal: I have an info element, which specifies the overall width and a red box within the cell, which already takes up some space. Furthermore, I want the text element to fill the remaining space, without pushing the red box out of the boundaries. Note, that the parent width and the box width could be dynamic values, depending on the screen resolution. I tried to wrap the according cell in another flex box combined with "flex: 1 1 0" and many other things, and ChatGPT also had no answer.
Do you have a solution? Or is it not solvable with the requirements?
.info {
width: 600px; /* dynamic */
background: lightgray;
}
.container {
background: gray;
}
.table {
display: table;
}
.row {
display: table-row;
}
.row :first-child {
border-right: solid black 20px;
}
.cell {
display: table-cell;
}
.flex {
display: flex;
}
.box {
width: 300px; /* dynamic */
background: red;
}
.text {
white-space: nowrap; /* needs to fill the remaining space, without pushing the box out of its parent */
}
<div class="info">
<div class="container">
<div class="table">
<div class="row">
<div class="cell">1.1</div>
<div class="cell ">1.2</div>
<div class="cell ">1.3</div>
</div>
<div class="row">
<div class="cell">2.1</div>
<div class="cell">
<div class="flex">
<div class="text">This is a text, too long to fit inside the container</div>
<div class="box"></div>
</div>
</div>
<div class="cell">2.3</div>
</div>
</div>
</div>
</div>
Each row can only consist of a single line, thus white-space: nowrap is required. That part of the text, that needs to be cut of, should be hidden with overlap: hidden.
2
Answers
Updated to reflect question edit
Here is an example using table markup.
The only way I can think of to make this work is using CSS grid and subgrid* to ensure consistent cell alignment across table rows
Please note that changing the display type on tables and lists affects accessibility – why you probably would have to add aria roles to support screen readers
*subgrid support
If you have a table, use
<table>
.Although it is quite dirty, you can wrap the text in
<div>
and addposition: absolute;
Example: