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
  • 981
  • 5
  • 20
cclloyd
  • 6,713
  • 15
  • 52
  • 84

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
  • 102,164
  • 10
  • 117
  • 144
1

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

j08691
  • 197,815
  • 30
  • 248
  • 265
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
  • 25
  • 3