Vertical (rotated) text in HTML table headers

↘锁芯ラ 提交于 2019-12-11 22:36:58

问题


My table headers are much wider than the data in the table, so I am trying to rotate the text in the headers to save space.

I've been trying out the suggestions in this question, and I've also taken a look at this and this.

However, none of the answers seem to actually work: here is my attempt in a JSFiddle.


The text can rotate, but the <th> elements don't resize properly, which was the whole point of trying to rotate the text.

Now that it's been 2-4 years since those questions have been asked, are there any new solutions to this problem?


回答1:


You could use CSS to select the thead and size the rows accordingly:

DEMO: http://jsfiddle.net/uo44ub6L/

CSS:

thead th {
    height: 130px;
}

Another method would be to use rowspan="5" to create a larger th but you would need to add some blank rows, and you would get the same effect. Either would work.

If you need to do this dynamically, you could use javascript to select the th and adjust the size on the span length and font size.



来源:https://stackoverflow.com/questions/25318555/vertical-rotated-text-in-html-table-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!