2013-02-15 83 views
3

嗨我想通過點擊一個按鈕在2秒內平穩過渡將HTML表格的高度從690更改爲400。有沒有辦法在純CSS中做到這一點?這裏是我的例子:如何在點擊鏈接時更改HTML表格的高度?

<html> 
<head> 
<title>Test</title> 
</head> 
<body> 
<table> 
<tr> 
<td> 
<button type="button">Click Me!</button> 
</td> 
</tr> 
<tr> 
<td height="690" width="1280> <--- This cell needs it height to change to 400px when the button is clicked. 
Cell 1 
</td> 
</tr> 
</table> 
</body> 
</html> 

回答

4

你不能CSS做純粹的,但是你可以很容易地jQuery做到這一點:

// Use a more specific selector by ID or class 
$('button').click(function (event) { 
    $(this).closest('tr').next().children('td:first').animate({height: 400}, 2000); 
}); 
1

您將需要使用Javascript。 使用function click() { document.getElementById('id').setProperty('style', 'height:100px;'); }

而且按鈕使用本 - <button onclick="click();">BUTTON</button>

0

給ID到按鈕(clickbut)和桌子(tableheight) 然後用jquery

$(document).ready(function(){ 
    $("#clickbut").click(function(){ 
    $("#tableheight").css('height','somevalue eg:300px'); 
    }); 
}); 
+0

哇,這個工作gre在,謝謝!有沒有辦法讓它平穩移動,就像過渡一樣? – william44isme 2013-02-16 08:34:17