How to prevent table cells with dashes from wrapping in HTML/CSS?
P粉254077747
2023-08-29 09:18:25
<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>
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.Just add white-space:nowrap in your CSS and it will make everything appear on one line. See
below