好吧,我完全重新编辑了这个,因为我更深入地研究了你的问题,发现空白是一个问题。
如我之前所说,使用
空白:预包装
避免变形。也有一个IE等价物。
首先,这里是一个示例,演示如何重新调整td元素的大小并删除其他元素的样式。它是硬编码的,但可以根据需要进行操作。
http://ece.arizona.edu/~justinvh/test.html
这是HTML:
<!DOCTYPE HTML>
<html>
<head>
<title>Testing Horizontal Accordion</title>
<style>
table {
width: 100%;
}
th {
display: table-cell !important;
}
td {
border: 1px solid #A8A8A8;
}
div.content {
max-height: 20px;
overflow: hidden;
white-space: pre-wrap;
}
</style>
<script src="jquery-1.3.2.min.js"></script>
</head>
<body>
<table>
<thead>
<tr>
<th style="width: 70%;">A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class='content'>Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby!
</div>
</td>
<td>
<div class='content'>Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby!
</div>
</td>
</tr>
<tr>
<td>
<div class='content'>Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby! Hello, my baby!
</div>
</td>
<td>Hello, my baby!</td>
</tr>
</tbody>
</table>
</body>
</html>
这里是javascript:
<script>
var $active = $("thead > tr > th:first");
var $active_td = $('div.content', 'table > tbody > tr > td:nth-child(1)');
var min_width = $active.next().width();
var max_width = $active.width();
$("thead > tr > th").each(function(i, e) {
(function(ith, element) {
$(element).click(function() {
$active_td.css('max-height', '20px');
$active.animate({ width: min_width }, { queue: false, duration: 400 });
$active_td = $('div.content', 'table > tbody > tr > td:nth-child(' + (ith + 1) + ')');
$active_td.css('max-height', 'inherit');
$(this).animate({ width: max_width }, { queue: false, duration: 400 });
$active = $(this);
});
})(i, e);
});
$('thead > tr > th:first').click();
</script>
所以,有些事情需要注意。我使用nth子选择器通过循环遍历每个th并应用一个使用环境的函数(以避免引用)来获取与th对应的td元素。这显然可以通过多种方式实现。
你可以在动画上使用“完成”回调来应用这个CSS,然后这样做。
我有意完全胜任
选择器,这样您就可以看到它们应该如何工作。您可以通过任何必要的方式添加标识符/类。
如果这对你有用,请告诉我。