[英]How to resize the tbody of html table vertically
我有一个带有固定标题的HTML table
。
因此, thead
是fixed
而tbody
是scrollable
。
现在,我想通过抓住tbody
的底部来调整table height(vertical only)
(例如,将resize
属性应用于textarea
),以便一次可以看到更多数据。
我认为您可以通过使用一点CSS来做到这一点,这非常简单。 这是垂直调整躯干大小的部分;
例如,将一个ID添加到您的tbody( <tbody id="tbody">
)。 这是CSS;
#tbody {
height: 500px; (a very tall tbody)
}
或一小;
#tbody {
height: 100px;
}
希望我能帮到您!
如果要使用jquery进行此操作,请执行以下操作:
$(document).ready(function(){
$("#your_table_id").css('height','250px');
});
要么
$(document).ready(function(){
$("#your_table_id").height($("#your_height_equal").height());
});
第二种方法是使高度等于另一个表或div等。
我想你正在寻找这样的东西
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<style>
#window {
width: 500px;
height: 400px;
min-width: 100px;
min-height: 100px;
border-bottom: 1px solid gray;
}
#header {
height: 25px;
line-height: 25px;
background-color: gray;
color: white;
text-align: center;
}
table {
min-height: 300px;
height: 100%;
width: 100%;
border-collapse: collapse;
}
#tableContainer {
position: absolute;
top: 25px;
bottom: 0px;
left: 0px;
right: 0px;
margin: 0;
padding: 0;
overflow: auto;
}
td {
padding: 5px;
margin: 0px;
border: 1px solid gray;
}
tr:last-child td {
border-bottom: none;
}
</style>
</head>
<body>
<div id="window">
<div id="header">Draggable Header</div>
<div id="tableContainer">
<table>
<thead>
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
$(document).ready(function () {
$('#window').draggable();
$('#window').resizable();
});
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.