当前位置: 首页 > 图文教程 > 网络编程 > Javascript > Firefox div高度自适应

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 Firefox div高度自适应


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 354 ::
收藏到网摘: n/a

IE不管设置div的高度与否,都会根据内容来自适应高度。但是FIrefox就没有这么聪明了。 1.如果div想要一个最小高度,那么应该用css的minheight这个属性,但是IE不支持,考虑到大多数用户都使用IE,所以一般情况下这个属性基本上弃置不用。在IE里面,height基本上就可以当作minheight来用,因为如果内容超出height,IE会自适应其高度。但是一旦设置了 height以后,FIrefox就不会自适应div的高度了。所以只能两个属性都不用,干干净净地写<div>Jimbor Studio</div>。
2.即使不设置固定高度,Firefox对高度的自适应也不那么尽人意。如果需要在一个层内嵌套一个需要float来规定的层,那它就又失灵了。其实有个最简单的方法,就是在div内的最下面加一个clear:both的div。例如:
复制代码 代码如下:

<div>
<div style="float:left;">Jmedia Design</div>
<div style="float:right;">www.jmedia.cn</div>
<div style="clear:both;"></div>
</div>

3.还有看到一个js解决的,也可以。
复制代码 代码如下:

<script type="text/javascript">
<!--
document.getElementById("box").style.height=document.getElementById("right").scrollHeight+20+"px"
-->
</script>