I have inherited a project where someone decided to set the display
for a td
to flex
. One of the consequences of this is that when there are other td
s in the row that span multiple lines, the td
with display: flex
does not stretch to the height of the other td
s.
The correct way to fix this (I think) would be to remove the display: flex
from the td
and have it on an inner div
, but I currently only have permissions to modify the CSS, so I'm wondering if there is any way to fix it with CSS only (while preserving the layout within the td
as shown in the made-up code snippet below)?
EDIT: The desired layout is to have a left and right side within the td
, the right side being a span
that is a colored dot. The colored dot needs to always be on the right and top aligned even on a mobile device when the td
is very narrow and the left side ends up wrapping.
table td {
border: 1px solid black;
}
td.flex {
display: flex;
justify-content: space-between;
}
span.right {
display: inline-block;
margin-left: 1em;
width: 1em;
border-radius: 50%
}
span.red {
background-color: red;
}
span.green {
background-color: green;
}
<table>
<tbody>
<tr>
<td class="flex"><span>Left </span><span class="right red"> </span></td>
<td>td with<br>multiple rows<br>blah blah blah</td>
</tr>
<tr>
<td class="flex"><span>Left side longer </span><span class="right red"> </span></td>
<td>td with<br>multiple rows<br>blah blah blah</td>
</tr>
<tr>
<td>
<div class="flex"><span>The right way to do it </span><span class="right green"> </span></div>
</td>
<td>td with<br>multiple rows<br>blah blah blah</td>
</tr>
</table>
table
is to act like a table. Applyingflexbox
will negate this in many respects. – Tricetbody
but never closed it. Also, your first 2td
tags are not wrapped intr
, however after them you included a</tr>
. – Coenosarctr
andtbody
are typos, I've added them. As per my post, I currently only have access to the CSS. I'm trying to determine if I can provide a CSS fix while I'm waiting for access to the HTML to do it properly. – Hadstdisplay: flex
I lose the right alignment of the colored dot. I would love to remove it if I can find a different way to achieve the layout without changing the HTML. – Hadst