如何将表列宽度设置为最长值,不包括标题 [英] How to set table column widths to the longest value, excluding header

查看:114
本文介绍了如何将表列宽度设置为最长值,不包括标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些带有HTML数据的表格。我试图找出如何动态设置列宽(最好用CSS)以适应最长的值,但我希望列标题是单词包装,因为它们相当长。



例如我有

 购买物品的百分比
40%
60%
30%

我希望列宽适合值40 %,60%,30%,并且具有购买的物品的百分比的字词包装。

解决方案



white-space:nowrap; 到您的 TD ,但不是你的 TH


I have some tables with data in HTML. I am trying to figure out how to dynamically set the column width (preferably with CSS) to fit the longest value, but I would like the column headers to be word wrapped because they are quite long in comparison.

For example I have

Percentage of Items purchased
40%
60%
30%

and I would like for the column width to fit the values 40%, 60%, 30%, and have "Percentage of Items purchased" word-wrapped.

解决方案

In your stylesheet Add:

white-space:nowrap; to your TD, but not to your TH.

这篇关于如何将表列宽度设置为最长值,不包括标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆