0

I have a list of span elements in a td with a fixed width.

I want to wrap the span elements, but no the words within the span elements.

So if I have

<td>
    <span>bind</span>
    <span>defaults</span>
    <span>nofail</span>
    <span>x-systemd.requires=zfs-mount.service</span>
    <span>bind</span>
    <span>defaults</span>
    <span>nofail</span>
    <span>x-systemd.requires=zfs-mount.service</span>
</td>

I want each span to go to a new line if needed, but not break the span in the middle.

How can I achieve this?

iamdhavalparmar
  • 1,090
  • 6
  • 23
cclloyd
  • 8,171
  • 16
  • 57
  • 104

3 Answers3

1

Set your spans to be display:inline-block

span {
  display: inline-block;
  border: 1px solid green;
}

td {
  border: 1px solid red;
}
<table>
  <tr>
    <td>
      <span>bind</span>
      <span>defaults</span>
      <span>nofail</span>
      <span>x-systemd.requires=zfs-mount.service</span>
      <span>bind</span>
      <span>defaults</span>
      <span>nofail</span>
      <span>x-systemd.requires=zfs-mount.service</span>
    </td>
  </tr>
</table>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
1

To keep the spans from breaking on the text, add white-space: nowrap; to the rules for your span.

j08691
  • 204,283
  • 31
  • 260
  • 272
0

white-space: nowrap;

https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

Try this out. I've posted the mozilla link as well.

Brian R
  • 35
  • 3