【DIV的问题高手进,溢出裁剪的问题】
一个固定行高的DIV,里面有一个三行一列的TABLE,DIV高度只够显示两行,第一和第三行固定有内容。 要求如果第二行有内容的时候,则把第一行顶到上面去,只显示二三行。能不能实现向上裁剪呢? 我试了一些代码都是第二行有内容时把第三行顶下去了。求可用代码,谢谢!
一个固定行高的DIV,里面有一个三行一列的TABLE,DIV高度只够显示两行,第一和第三行固定有内容。 要求如果第二行有内容的时候,则把第一行顶到上面去,只显示二三行。能不能实现向上裁剪呢? 我试了一些代码都是第二行有内容时把第三行顶下去了。求可用代码,谢谢!
答案:这个不需要js哦,css就可以实现。为了让效果更突出一些,这里设div300px高,每个td都是100px高,这样,有三行td的时候,第一行就不显示了。闲话少叙,代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>example</title> <style type="text/css"> <!-- body{ font:12px Arial, Helvetica, sans-serif;} .divcon{ height:200px; overflow:hidden; position:relative; width:400px;} .divcon table{ bottom:0; left:0; position:absolute;} --> </style> </head> <body> <div class="divcon"> <table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="100" bgcolor="#eeeeee">1111111</td> </tr> <tr> <td height="100" bgcolor="#dddddd">2222222</td> </tr> <tr> <td height="100" bgcolor="#cccccc">3333333</td> </tr> </table> </div> </body> </html>
其他:路过...................... <div style="height:50px;overflow:hidden;">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25">#1</td>
</tr>
<tr>
<td height="25">#2</td>
</tr>
<tr>
<td height="25">#3</td>
</tr>
</table>
</div>
要求如果第二行有内容的时候,则把第一行顶到上面去,只显示二三行。能不能实现向上裁剪呢?
回答: 只能用js判断了,你会写不! 会就自己写写 js 楼上的html加下面的js:
<script>
document.getElementsByTagName('div')[0].scrollTop=900000;
</script>
上一个:HTML代码中如何用POSITION属性来固定一个DIV模块的位置,让其不随滚动条移动?
下一个:网页JS和DIV