3

I have the following table:

table {
  border-collapse: collapse;
}

th,
td {
  border: 1px solid black;
  text-align: left;
}

.header {
  display: inline-flex;
}
  <table>
    <thead>
      <tr>
        <th>
          <div class="header">
            <div>&#8592;</div>
            <div>aaaaaaaaa aa</div>
            <div>&#8594;</div>
          </div>
        </th>
        <th>
          <div class="header">
            <div>&#8592;</div>
            <div>bbbbbbbbb bbbbbbbb bbbbbbb</div>
            <div>&#8594;</div>
          </div>
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>aaaaaaaaaaaaaaaaaaaaa</td>
        <td>bbbbbbb</td>
      </tr>
    </tbody>
  </table>

What I want to achieve is to keep the right arrow of each header always close to the caption, even if the text wraps because of window (and table) resize.

This is the situation when table is not resized (and it's ok):

enter image description here

This is the situation when table is resized (not ok):

enter image description here

This is what I want when table is resized:

enter image description here

For the last case I used flex: 0 on the caption div, but this will force text wrap even in the first case, and I don't want it.

Here is the jsfiddle

Thanks in advance!

Fab
  • 4,526
  • 2
  • 21
  • 45
  • Can you elaborate what you mean by "but this will force text wrap even in the first case"? – ArSeN Mar 08 '19 at 09:58
  • @ArSeN if table as enough space to keep text on a single line for each column header, text will be wrapped, and the first image will be like the last one https://jsfiddle.net/pqkbwdcj/ – Fab Mar 08 '19 at 10:03
  • 1
    You can't do this with css, as soon as you text wraps, the container is 100% width - the duplicate is what is happening with inline block elements instead of words – Pete Mar 08 '19 at 10:03

0 Answers0