How to prevent table cells with dashes from wrapping in HTML/CSS?
P粉254077747
P粉254077747 2023-08-29 09:18:25
0
2
598

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.

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:

| Description | Date | |----------------------------|----------| | This is a really long | 2022-10- | | description cell with many | 12 | | lines... | |

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 , which works for spaces but not dashes.

Should I use non-shrinking flex elements?


By shortening the description, I mean:

| Description | Date | |--------------------------|---------------------| | This is a really long | 2022-10-12 | | description cell with | | | many lines... | |

P粉254077747
P粉254077747

reply all (2)
P粉133321839

You should usewhite-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 addwhite-space:nowrapin 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; }
    Description Date
    This is a really long description cell with many lines 2022-10-12
      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!