I have two tables on either side of a centered div. I'd like the content in the left-hand table to be aligned on the right, and the content in the right-hand table to be aligned on the left. I managed to do so by creating an extra column in the left-hand table and setting width: 100%
on the first cells and white-space: nowrap
on the second cells.
The problem is, because of the nowrap
property, the content overflows when the tables are too small. I tried setting word-wrap: break-word
in vain. How can I force the content to fit the table width?
Here is my code so far: JSFIDDLE
#container {
height: 180px;
display: flex;
flex-flow: row;
align-items: stretch;
border: 1px dotted gray;
}
table {
flex: 1;
display: flex;
margin: 10px;
overflow-y: scroll;
overflow-x: hidden;
border: 1px dashed blue;
}
tbody {
display: block;
margin: auto 0;
}
td {
padding: 5px;
border: 1px solid red;
}
#left td:nth-child(1){
width: 100%;
}
#left td:nth-child(2) {
white-space: nowrap;
}
#list, #center {
width: 100px;
margin: 10px;
border: 1px dotted gray;
}
<div id="container">
<div id="list"></div>
<table id="left">
<tbody>
<tr>
<td></td>
<td>Lorem ipsum dolor sit amet</td>
</tr>
<tr>
<td></td>
<td>Valar morghulis</td>
</tr>
<tr>
<td></td>
<td>One fish, two fish, red fish, blue fish</td>
</tr>
</tbody>
</table>
<div id="center"></div>
<table id="right">
<tbody>
<tr><td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td></tr>
<tr><td>The quick brown fox jumps over the lazy dog</td></tr>
<tr><td>Would you kindly help me out</td></tr>
<tr><td>Supercalifragilisticexpialidocious</td></tr>
<tr><td>Alpha</td></tr>
<tr><td>Bravo</td></tr>
<tr><td>Charlie</td></tr>
<tr><td>Delta</td></tr>
<tr><td>Echo</td></tr>
<tr><td>Foxtrot</td></tr>
<tr><td>Golf</td></tr>
</tbody>
</table>
</div>
How about this: DEMO
Remove the extra column and add
margin-left:auto
to lefttbody
Remove the nowrap