HTML表溢出不起作用

时间:2018-03-09 07:16:02

标签: html css html-table overflow oracle-apex

我想在html表体溢出时添加一个滚动条。我不想滚动表头。我在我的oracle apex页面中有这些html和css代码

HTML

<div class="t-Report-wrap">
<div class="t-Report-tableWrap">
    <table class="t-Report-report" summary="tab">
        <thead>
            <tr>
                <th class="t-Report-colHead" id="CODE" align="center">Code</th>
                <th class="t-Report-colHead" id="HEAD" align="center">Head</th>
            </tr>
        </thead>            
        <tbody>
            <tr> <td > 5198 </td><td >SUSPENCE </td></tr>
            <tr> <td > 1308 </td><td >SHARE IN KNR</td></tr>
            <tr> <td > 4803 </td><td >ONE TIME </td></tr>
            <tr><td >6021</td><td >NEETHI GOODS </td></tr>
            <tr><td >6022</td><td >MANNURE STOCK </td></tr>
            <tr><td >4832</td><td >DONATION TO </td></tr>
            <tr><td >5218</td><td >CALANDER </td></tr>
            <tr><td >4829</td><td >BUILDING TAX </td></tr>
            <tr><td >5199</td><td >BICYCLE ADVANCE </td></tr>
            <tr><td >2509</td><td >BANK LOAN LT MI(SPL) </td></tr>
        </tbody>
    </table>
</div>
<div class="t-Report-links"></div>
<table class="t-Report-pagination t-Report-pagination--bottom" role="presentation"></table> 
</div>

CSS

.t-Report-wrap {
    position: relative;
}
.t-Report-tableWrap {
    height:180px;
    overflow:auto;  
    margin-top:20px;
}
.t-Report-tableWrap table {
    width:100%;
}
.t-Report-tableWrap table thead th .t-Report-colHead {
    position:absolute;   
    top:-20px;
    z-index:2;
    height:20px;
    width:35%;
    border:1px solid red;
}

但是使用此代码,表头也是滚动的。这是从SO回答How to display scroll bar onto a html table引用的。任何人都可以帮我找出这段代码中的错误吗?

5 个答案:

答案 0 :(得分:2)

更新您的th HTML以包含span

<th id="CODE" align="center"><span class="t-Report-colHead">Code</span></th>

编辑CSS选择器以删除重复的th

.t-Report-tableWrap table thead .t-Report-colHead

答案 1 :(得分:1)

设置高度并将overflow:auto;添加到.t-Report-tableWrap tbody而不是.t-Report-tableWrap,以便滚动只会影响表格主体。

.t-Report-wrap {
    position: relative;
}
.t-Report-tableWrap {  
    margin-top:20px;
}
.t-Report-tableWrap table {
    width:100%;
}
.t-Report-tableWrap table thead th .t-Report-colHead {
    position:absolute;   
    top:-20px;
    z-index:2;
    height:20px;
    width:35%;
    border:1px solid red;
}
.t-Report-tableWrap tbody{
    height:180px;
    overflow:auto;
}

希望这有帮助。

答案 2 :(得分:1)

更改css代码

tbody {
    display:block;
    height:200px;
    overflow:auto;
}
thead, tbody tr {
    display:table;
    width:100%;
    table-layout:fixed;/* even columns width , fix width of table too*/
}
thead {
    width: calc( 100% - 1em )/* scrollbar is average 1em/16px width, remove it from thead width */
}
t-Report-report {
    width:400px;
}
<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<div class="t-Report-wrap">
		<div class="t-Report-tableWrap">
			<table class="t-Report-report" summary="tab">
				<thead>
					<tr>
						<th align="center" class="t-Report-colHead" id="CODE">Code</th>
						<th align="center" class="t-Report-colHead" id="HEAD">Head</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>5198</td>
						<td>SUSPENCE</td>
					</tr>
					<tr>
						<td>1308</td>
						<td>SHARE IN KNR</td>
					</tr>
					<tr>
						<td>4803</td>
						<td>ONE TIME</td>
					</tr>
					<tr>
						<td>6021</td>
						<td>NEETHI GOODS</td>
					</tr>
					<tr>
						<td>6022</td>
						<td>MANNURE STOCK</td>
					</tr>
					<tr>
						<td>4832</td>
						<td>DONATION TO</td>
					</tr>
					<tr>
						<td>5218</td>
						<td>CALANDER</td>
					</tr>
					<tr>
						<td>4829</td>
						<td>BUILDING TAX</td>
					</tr>
					<tr>
						<td>5199</td>
						<td>BICYCLE ADVANCE</td>
					</tr>
					<tr>
						<td>2509</td>
						<td>BANK LOAN LT MI(SPL)</td>
					</tr>
				</tbody>
			</table>
		</div>
		<div class="t-Report-links"></div>
		<table class="t-Report-pagination t-Report-pagination--bottom" role="presentation"></table>
	</div>
</body>
</html>

答案 3 :(得分:1)

您的代码不正确,因为您在th

中的.t-Report-colHead.t-Report-tableWrap table thead th .t-Report-colHead {之间添加了额外的空格

但是,这是一个有效的代码。

tr{
  display: table;
  width: 100%;
  table-layout: fixed;
}

thead{
  display: block;
}

tbody{
  display: block;
  height: 180px;
  overflow: auto;
}

CODEPEN

希望这有帮助。

答案 4 :(得分:0)

我认为apex有此设置,请参阅此示例:

没有设置: https://apex.oracle.com/pls/apex/f?p=145797:1

设置: https://apex.oracle.com/pls/apex/f?p=145797:12

转到报告属性: enter image description here