简体   繁体   中英

How to make HTML table cells expand horizontally beyond end of page?

I have a table with many columns. The table is wider than the page, and so it scrolls. The default behaviour of tables seems to be to make the width of each column as small as possible, and allow text to spill over onto a new line.

I'd like instead for my table cells to grow horizontally with their contents, and never to spill over onto a second line. Is this possible using CSS? If not, does anyone have any pointers for how I might start to do this using Javascript (jQuery if poss)?

You can use:

td {
  white-space: nowrap;
}

I think this might be what you want. http://geekswithblogs.net/TimH/archive/2006/04/16/75318.aspx

Using the

 white-space: nowrap;

will cause the cell to take up as much space as it needs.

您可以将表格宽度设置为100%或*。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM