How to prevent table cells with dashes from wrapping in HTML/CSS?
P粉254077747
P粉254077747 2023-08-29 09:18:25
0
2
650
<p>I know my question looks very similar to this one: How to prevent text wrapping in table cells, this was the first one I checked. </p> <p>I have a table and in one of the columns I will write a long description and the next column is the date. Browsers think it's cool to wrap date columns because they are dash-separated strings. Currently I have something like this: </p> <pre class="brush:php;toolbar:false;">| Description | Date | |----------------------------|----------| | This is a really long | 2022-10- | | description cell with many | 12 | | lines... | |</pre> <p>How do I tell the browser that I want my description cells to be slightly shorter and the date column not to wrap. In the solution I read, it said you should use <code><td wrap="nowrap"></code>, which works for spaces but not dashes. </p> <p>Should I use non-shrinking flex elements? </p> <hr /> <p>By shortening the description, I mean: </p> <pre class="brush:php;toolbar:false;">| Description | Date | |--------------------------|---------------------| | This is a really long | 2022-10-12 | | description cell with | | | many lines... | |</pre></p>
P粉254077747
P粉254077747

reply all(2)
P粉133321839

You should use white-space: nowrap; for date columns. I'm not sure what you mean when you say you want the description cells to be shorter? Just adjust the width to get the desired result.

P粉340980243

Just add white-space:nowrap in your CSS and it will make everything appear on one line. See

below

table {
  border-collapse: collapse;
  width: 100px;
}

td {
  border: 1px solid gray;
  padding: 0.25rem 0.5rem;
}

td:last-child {
  white-space: nowrap;
}
<table>
  <tr>
    <td>Description</td>
    <td>Date</td>
  </tr>
  <tr>
    <td>This is a really long description cell with many lines</td>
    <td>2022-10-12</td>
  </tr>
</table>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!