使第一列固定,下一列在 html 表中可滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11815882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make first column fixed and next column scrollable in html Table
提问by monda
I have a table with only two columns . i want to make first column is fixed and next column scrollable in all the rows..it should be horizontally scrollable as a whole .. not individual columns
我有一个只有两列的表。我想让第一列是固定的,下一列可以在所有行中滚动..它应该作为一个整体水平滚动..不是单个列
There can be hundreds of rows. .
可以有数百行。.
I have a demo code here in Jsfiddle
我在Jsfiddle 中有一个演示代码
I dont have much exposure to css styling.
我对 css 样式的接触不多。
回答by neokio
You could use CSS overflow:auto;
, as in http://jsfiddle.net/Yw679/2/
您可以使用 CSS overflow:auto;
,如http://jsfiddle.net/Yw679/2/
If I understand correctly, you want the entire left column to be static, and the entire right column (including the header) to be horizontally scrollable. Is that correct?
如果我理解正确,您希望整个左列都是静态的,并且整个右列(包括标题)都可以水平滚动。那是对的吗?
If so, it's not possible with one table. But with a bit of extra code, it's possible with two tables like this: http://jsfiddle.net/Yw679/6/
如果是这样,一张桌子是不可能的。但是通过一些额外的代码,可以使用这样的两个表:http: //jsfiddle.net/Yw679/6/
回答by Robin Maben
回答by user3146706
I think you want to do something like this example
我想你想做类似这个例子的事情
https://www.datatables.net/extensions/fixedcolumns/examples/initialisation/left_right_columns.html
https://www.datatables.net/extensions/fixedcolumns/examples/initialisation/left_right_columns.html
回答by Prakash Bhavnath
回答by Max Girkens
You could do something like this:
你可以这样做:
th{
display :inline-block;
height: 50px;
width: 100px;
overflow: scroll;
}
th:first-child{
overflow: hidden;
}
?
?