HelloWorld
HelloWorld

Reputation: 2455

Table column width as needed (HTML/CSS)

When tables are rendered the table usually only takes up 100% of the screen (if it is big enough) and then the columns get as little space each as is possible. Typically the columns will get as much space as the longest non-breakable content requires. How can I make things so that each column will get as much space as its longest content, even if that means the table will have to take up more than 100% of the screen width? I want each column to be as long as its longest content, regardless of how much space the table will have to consume.

Upvotes: 2

Views: 1470

Answers (1)

Patrick Allen
Patrick Allen

Reputation: 2168

Try this:

td {
    white-space: nowrap;
}

This makes it so the text in each table data cell will not wrap.

Proof it works: Here.

Upvotes: 4

Related Questions