Javascript 尝试在HTML中制作固定的表格标题、滚动和可见性问题?
我一直在尝试用HTML制作一个带有固定标题的表(必要时还有一个水平滚动条)。这个JSFIDLE显示了我到目前为止所拥有的:Javascript 尝试在HTML中制作固定的表格标题、滚动和可见性问题?,javascript,jquery,css,html,Javascript,Jquery,Css,Html,我一直在尝试用HTML制作一个带有固定标题的表(必要时还有一个水平滚动条)。这个JSFIDLE显示了我到目前为止所拥有的: html, body { margin:0; padding:0; height:100%; } .horizontalscrollcontainer { position: relative; padding-top: 37px; overflow:auto; } .verticalscrollcontainer {
html, body {
margin:0;
padding:0;
height:100%;
}
.horizontalscrollcontainer {
position: relative;
padding-top: 37px;
overflow:auto;
}
.verticalscrollcontainer {
background:transparent;
overflow-y:auto;
overflow-x:visible;
height: 200px;
}
table {
border-spacing: 0;
width:120%;
}
td + td {
border-left:1px solid #eee;
}
td, th {
border-bottom:1px solid #eee;
background: #ddd;
color: black;
padding: 10px 25px;
}
th {
height: 0;
line-height: 0;
padding-top: 0;
padding-bottom: 0;
color: transparent;
border: none;
white-space: nowrap;
}
th div {
position: absolute;
background: transparent;
color: black;
padding: 9px 25px;
top: 0px;
margin-left: -25px;
line-height: normal;
border-left: 1px solid #800;
}
th:first-child div {
border: none;
}
<div class="horizontalscrollcontainer">
<div class="verticalscrollcontainer">
<table>
<thead>
<tr class="header">
<th>Table attribute name
<div>Table attribute name</div>
</th>
<th>Value
<div>Value</div>
</th>
<th>Description
<div>Description</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>align</td>
<td>left, center, right</td>
<td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the alignment of a table according to surrounding text</td>
</tr>
<tr>
<td>bgcolor</td>
<td>rgb(x,x,x), #xxxxxx, colorname</td>
<td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the background color for a table</td>
</tr>
<tr>
<td>border</td>
<td>1,""</td>
<td>Specifies whether the table cells should have borders or not</td>
</tr>
<tr>
<td>cellpadding</td>
<td>pixels</td>
<td>Not supported in HTML5. Specifies the space between the cell wall and the cell content</td>
</tr>
<tr>
<td>cellspacing</td>
<td>pixels</td>
<td>Not supported in HTML5. Specifies the space between cells</td>
</tr>
<tr>
<td>frame</td>
<td>void, above, below, hsides, lhs, rhs, vsides, box, border</td>
<td>Not supported in HTML5. Specifies which parts of the outside borders that should be visible</td>
</tr>
<tr>
<td>rules</td>
<td>none, groups, rows, cols, all</td>
<td>Not supported in HTML5. Specifies which parts of the inside borders that should be visible</td>
</tr>
<tr>
<td>summary</td>
<td>text</td>
<td>Not supported in HTML5. Specifies a summary of the content of a table</td>
</tr>
<tr>
<td>width</td>
<td>pixels, %</td>
<td>Not supported in HTML5. Specifies the width of a table</td>
</tr>
</tbody>
</table>
</div>
</div>
html,正文{
保证金:0;
填充:0;
身高:100%;
}
.水平滚动容器{
位置:相对位置;
填充顶部:37px;
溢出:自动;
}
.垂直滚动容器{
背景:透明;
溢出y:自动;
溢出x:可见;
高度:200px;
}
桌子{
边界间距:0;
宽度:120%;
}
td+td{
左边框:1px实心#eee;
}
td,th{
边框底部:1px实心#eee;
背景:ddd;
颜色:黑色;
填充:10px 25px;
}
th{
身高:0;
线高:0;
填充顶部:0;
填充底部:0;
颜色:透明;
边界:无;
空白:nowrap;
}
第四分区{
位置:绝对位置;
背景:透明;
颜色:黑色;
填充:9px 25px;
顶部:0px;
左边距:-25px;
线高:正常;
左边框:1px实心#800;
}
th:第一儿童组{
边界:无;
}
表属性名称
表属性名称
价值
价值
描述
描述
排列
左、中、右
HTML5中不支持。在HTML4.01中已弃用。根据周围文字指定表格的对齐方式
bgcolor
rgb(x,x,x),#xxxxxx,颜色名称
HTML5中不支持。在HTML4.01中已弃用。指定表格的背景色
边境
1,""
指定表格单元格是否应有边框
细胞填充
像素
HTML5中不支持。指定单元墙和单元内容之间的空间
细胞间距
像素
HTML5中不支持。指定单元格之间的间距
框架
空白、上方、下方、侧面、左侧、右侧、侧边、方框、边框
HTML5中不支持。指定外部边框的哪些部分应可见
规则
无、组、行、列、全部
HTML5中不支持。指定内部边框的哪些部分应可见
总结
文本
HTML5中不支持。指定表内容的摘要
宽度
像素,%
HTML5中不支持。指定表格的宽度
我遇到的问题是,水平滚动条似乎位于verticalscrollcontainer而不是horizontalscrollcontainer上。是否有办法对此进行调节(溢出-x自动设置为自动,因为溢出-y设置为自动)
谢谢你的建议 我认为您最好将标题从容器中取出:
<div class="xclass">
<table>
<thead>
<tr class="header">
<th>Table attribute name
<div class="headerdiv">Table attribute name</div>
</th>
<th>Value
<div>Value</div>
</th>
<th>Description
<div>Description</div>
</th>
</tr>
</thead>
</table>
</div>
表属性名称
表属性名称
价值
价值
描述
描述
检查这把小提琴-我想你需要在css中使用它:
table thead{position:fixed;}
我将分成两部分,并指定宽度(%如果响应)
A.
B
A.
B
A.
B
A.
B
CSS。。。。
#桌子{
溢出y:自动;
高度:150像素;
边框底部:1px纯色灰色;
}
桌子{
宽度:100%;
}
表td,表th{
边框颜色:灰色;
边框:1px实心;
宽度:50%;
}
使用此选项可以帮助您
<style>
html, body {
margin:0;
padding:0;
height:100%;
}
.container {
position:relative;
background:transparent;
top:0px;
overflow:auto;
width: 100%;
height: 200px;
}
table {
border-spacing: 0;
width:120%;
}
td + td {
border-left:1px solid #eee;
}
td, th {
border-bottom:1px solid #eee;
background: #ddd;
color: black;
padding: 10px 25px;
}
th {
height: 0;
line-height: 0;
padding-top: 0;
padding-bottom: 0;
color: transparent;
border: none;
white-space: nowrap;
}
th:first-child div {
border: none;
}
.wrap {
width: 617px;
}
.wrap table {
width: 600px;
table-layout: fixed;
}
</style>
</head>
<body>
<div class="wrap">
<table class="head">
<tr>
<td>Table attribute name</td>
<td>Value</td>
<td>Description</td>
</tr>
</table>
<div class="container">
<table>
<tr>
<td>align</td>
<td>left, center, right</td>
<td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the alignment of a table according to surrounding text</td>
</tr>
<tr>
<td>bgcolor</td>
<td>rgb(x,x,x), #xxxxxx, colorname</td>
<td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the background color for a table</td>
</tr>
<tr>
<td>border</td>
<td>1,""</td>
<td>Specifies whether the table cells should have borders or not</td>
</tr>
<tr>
<td>cellpadding</td>
<td>pixels</td>
<td>Not supported in HTML5. Specifies the space between the cell wall and the cell content</td>
</tr>
<tr>
<td>cellspacing</td>
<td>pixels</td>
<td>Not supported in HTML5. Specifies the space between cells</td>
</tr>
<tr>
<td>frame</td>
<td>void, above, below, hsides, lhs, rhs, vsides, box, border</td>
<td>Not supported in HTML5. Specifies which parts of the outside borders that should be visible</td>
</tr>
<tr>
<td>rules</td>
<td>none, groups, rows, cols, all</td>
<td>Not supported in HTML5. Specifies which parts of the inside borders that should be visible</td>
</tr>
<tr>
<td>summary</td>
<td>text</td>
<td>Not supported in HTML5. Specifies a summary of the content of a table</td>
</tr>
<tr>
<td>width</td>
<td>pixels, %</td>
<td>Not supported in HTML5. Specifies the width of a table</td>
</tr>
</table>
</div>
</div>
html,正文{
保证金:0;
填充:0;
身高:100%;
}
.集装箱{
位置:相对位置;
背景:透明;
顶部:0px;
溢出:自动;
宽度:100%;
高度:200px;
}
桌子{
边界间距:0;
宽度:120%;
}
td+td{
左边框:1px实心#eee;
}
td,th{
边框底部:1px实心#eee;
背景:ddd;
颜色:黑色;
填充:10px 25px;
}
th{
身高:0;
线高:0;
填充顶部:0;
填充底部:0;
颜色:透明;
边界:无;
空白:nowrap;
}
th:第一儿童组{
边界:无;
}
.包裹{
宽度:617px;
}
.包桌子{
宽度:600px;
表布局:固定;
}
表属性名称
价值
描述
排列
左、中、右
HTML5中不支持。在HTML4.01中已弃用。根据周围文字指定表格的对齐方式
bgcolor
rgb(x,x,x),#xxxxxx,颜色名称
HTML5中不支持。在HTML4.01中已弃用。指定表格的背景色
边境
1,""
指定
<style>
html, body {
margin:0;
padding:0;
height:100%;
}
.container {
position:relative;
background:transparent;
top:0px;
overflow:auto;
width: 100%;
height: 200px;
}
table {
border-spacing: 0;
width:120%;
}
td + td {
border-left:1px solid #eee;
}
td, th {
border-bottom:1px solid #eee;
background: #ddd;
color: black;
padding: 10px 25px;
}
th {
height: 0;
line-height: 0;
padding-top: 0;
padding-bottom: 0;
color: transparent;
border: none;
white-space: nowrap;
}
th:first-child div {
border: none;
}
.wrap {
width: 617px;
}
.wrap table {
width: 600px;
table-layout: fixed;
}
</style>
</head>
<body>
<div class="wrap">
<table class="head">
<tr>
<td>Table attribute name</td>
<td>Value</td>
<td>Description</td>
</tr>
</table>
<div class="container">
<table>
<tr>
<td>align</td>
<td>left, center, right</td>
<td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the alignment of a table according to surrounding text</td>
</tr>
<tr>
<td>bgcolor</td>
<td>rgb(x,x,x), #xxxxxx, colorname</td>
<td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the background color for a table</td>
</tr>
<tr>
<td>border</td>
<td>1,""</td>
<td>Specifies whether the table cells should have borders or not</td>
</tr>
<tr>
<td>cellpadding</td>
<td>pixels</td>
<td>Not supported in HTML5. Specifies the space between the cell wall and the cell content</td>
</tr>
<tr>
<td>cellspacing</td>
<td>pixels</td>
<td>Not supported in HTML5. Specifies the space between cells</td>
</tr>
<tr>
<td>frame</td>
<td>void, above, below, hsides, lhs, rhs, vsides, box, border</td>
<td>Not supported in HTML5. Specifies which parts of the outside borders that should be visible</td>
</tr>
<tr>
<td>rules</td>
<td>none, groups, rows, cols, all</td>
<td>Not supported in HTML5. Specifies which parts of the inside borders that should be visible</td>
</tr>
<tr>
<td>summary</td>
<td>text</td>
<td>Not supported in HTML5. Specifies a summary of the content of a table</td>
</tr>
<tr>
<td>width</td>
<td>pixels, %</td>
<td>Not supported in HTML5. Specifies the width of a table</td>
</tr>
</table>
</div>
</div>
<section class="">
<div class="container">
<table>
<thead>
<tr class="header">
<th>Table attribute name
</th>
<th>Value
</th>
<th>Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>align</td>
<td>left, center, right</td>
<td>Not supported in HTML5. Deprecated in HTML 4.01. Specifies the alignment of a table according to surrounding text</td>
</tr>
</tbody>
</table>
</div>
html, body {
margin:0;
padding:0;
height:100%;
}
.container {
background:transparent;
overflow:auto;
width: 100%;
height: 200px;
}
table {
border-spacing: 0;
width:120%;
}
td, th {
border-bottom:1px solid #eee;
background: #ddd;
color: black;
padding: 9px 25px
}
th:nth-of-type(1), td:nth-of-type(1){
width:200px;
}
th:nth-of-type(2), td:nth-of-type(2){
width:100px;
}
th:nth-of-type(3), td:nth-of-type(3){
width:200px;
}
td + td {
border-left:1px solid #eee;
}
thead {
position:absolute;
border: none;
top:0px;
}
tbody{
margin-top:38px;
display:block;
}