css+div自动适应高度,在IE和firefox下都能适应 (左右DIV自适应高度)

简介:
网上找了些css+div自动适应高度的代码,用起来总是不对,这里求大侠们一段css+div自动适应高度的代码
 有两个问题:
   第一:div根据内容自动调整div的高度
   第二:左右结构的div,无论当左边的div还是右边的div高度增大时,高度小的div能自动调整高度,并且下方的div也自动往下移动位置
   
   希望大侠们不吝赐教,困惑好长时间了,希望在这里能够得到解决。


 

我用了下面这种方法,很容易解决。

 

< style  type = "text/css" >
#leftbox{float:left;width:200px; background-color:#FF0000;}
#midbox{float:left;width:200px;background-color:#FFFF00}
.bottom{display:block;clear:both;margin-top:50px;background:#000000;width:300px;height:200px;color:#FFF;}
</ style >
< div  id = "leftbox" >22</ div >
< div  id = "midbox" >左边的内容左边的内容左边的内容左边的内容左边的内容左边的内容左边的内容</ div >
< script >
if(midbox.offsetHeight>leftbox.offsetHeight)
leftbox.style.height=midbox.offsetHeight+"px";
else
midbox.style.height=leftbox.offsetHeight+"px";
</ script >
< div  class = "bottom" >sssssssssssss</ div >

 

 

下面论坛上别人的答案。

 ---------------------------

 

三列自适应高度
可以根据自己需要修改
兼容IE6 IE7 IE8 FireFox Chrome Opera Safari Netscape
XML/HTML code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!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 >无标题文档</ title >
< style  type = "text/css" >
<!--
.main{
       width:600px;
       overflow:hidden;
       }
.left{
       background:#999999;
       margin-bottom:-10000px;
       padding-bottom:10000px;
       width:200px;
       float:left;
       color:#FF0000;    
       }
.center{
       background:#333333;
       margin-bottom:-10000px;
       padding-bottom:10000px;
       width:200px;
       float:left;
       color:#FF0000;
       }
.right{
       background:#0000FF;
       margin-bottom:-10000px;
       padding-bottom:10000px;
       width:200px;
       float:left;
       }
.bottom{
       width:600px;
       background:#CC00CC;
       color:#000000;
       height:100px;
       }
-->
</ style >
</ head >
 
< body >
< div  class = "main" >
    < div  class = "left" >left</ div >
    < div  class = "center" >center< br  />center< br  />center< br  />center< br  />center< br  />center< br  />center< br  /></ div >
    < div  class = "right" >right</ div >
</ div >
< div  class = "bottom" >bottom</ div >
</ body >
</ html >

---------------------------------------

用javascript,类似:
document.getElementById("firstindex_left").style.height = document.getElementById("pmain").offsetHeight + "px"; 
--------------------------------------

<!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>
    <title>New Document </title>
    <style type="text/css">
body{
margin:15px;
font-family:Arial; font-size:12px;
}
.father{
background-color:#ffff99;
border:1px solid #111111;
padding:5px;
float:left;
width:100%;
}
.father div{
padding:10px;
margin:0px 15px;
border:1px dashed #111111;
background-color:#90baff;
display:inline;
}
.son1{
float:left;
}
.son2{
float:left;
}
.son3{
float:right;
}
</style>
</head>
<body>
    <div class="father">
        <div class="son1">
            Box-1</div>
        <div class="son2">
            Box-2</div>
        <div class="son3">
            Box-3</div>
    </div>
</body>
</html>
 

 

--------------------------------------- 

XML/HTML code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
< HTML >
  < HEAD >
   < TITLE > New Document </ TITLE >
   < META  NAME = "Generator"  CONTENT = "EditPlus" >
   < META  NAME = "Author"  CONTENT = "" >
   < META  NAME = "Keywords"  CONTENT = "" >
   < META  NAME = "Description"  CONTENT = "" >
  </ HEAD >
< style >
.container{
                     display:table;
                     width:600px;
                     background:#ff6600;
                     margin:0px;
                     padding-top:0;
                     padding-right:0;
                     padding-bottom:0;
                     padding-left:0;
                     }
.leftbox{
                 width:300px;
                 background:#f00;
                 float:left;
             
                 height:100%;
                 
                 }
.rightbox{
                     width:300px;
                     height:100%;
                     background:#c90;
                     float:right;
                     }
</ style >
  < BODY >
   < div  class = "container" >
         < div  class = "leftbox" >
             就何必何必何必何必何必何必何必何必何必何必
         </ div >
 
         < div  class = "rightbox" >
             必何必何必何必何必何必何必何必何必何必何必何必何必必何必何必何必何必何必何必何必何必何必何必何必何必何必何必何必必何必何必何
     </ div >
  </ BODY >
</ HTML >

 本文转自kenty博客园博客,原文链接http://www.cnblogs.com/kentyshang/archive/2012/11/16/2773135.html如需转载请自行联系原作者


kenty

相关文章
|
29天前
|
人工智能 程序员 UED
【01】完成新年倒计时页面-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子
【01】完成新年倒计时页面-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子
117 21
【01】完成新年倒计时页面-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子
|
27天前
|
前端开发 JavaScript
【02】v1.0.1更新增加倒计时完成后的放烟花页面-优化播放器-优化结构目录-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子
【02】v1.0.1更新增加倒计时完成后的放烟花页面-优化播放器-优化结构目录-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子
52 14
【02】v1.0.1更新增加倒计时完成后的放烟花页面-优化播放器-优化结构目录-蛇年新年快乐倒计时领取礼物放烟花html代码优雅草科技央千澈写采用html5+div+CSS+JavaScript-优雅草卓伊凡-做一条关于新年的代码分享给你们-为了C站的分拼一下子
|
5月前
|
Web App开发 JavaScript 前端开发
添加浮动按钮点击滚动到网页底部的纯JavaScript演示代码 IE9、11,Maxthon 1.6.7,Firefox30、31,360极速浏览器7.5.3.308下测试正常
添加浮动按钮点击滚动到网页底部的纯JavaScript演示代码 IE9、11,Maxthon 1.6.7,Firefox30、31,360极速浏览器7.5.3.308下测试正常
|
3月前
div+css3制作的简洁404错误页面特效源码
div+css3制作的简洁404错误页面特效源码是一段实现了非常简单也大方的效果的网站404错误页面效果代码,当鼠标经过404数字时,该数字会发光发亮,本段代码适应于所有网站使用,有需要的朋友们可以前来下载使用。本段代码兼容目前最新的各类主流浏览器,是一款非常优秀的特效源码。
33 1
|
5月前
|
JavaScript 前端开发
网页前端课程设计-【模仿】香港中文大学官网,轮播图及div+css布局,js的dom操作
这篇文章介绍了如何模仿香港中文大学官网进行网页前端课程设计,包括使用div+css布局、js的DOM操作以及实现轮播图等技术细节。
|
7月前
|
前端开发
css 拉伸 resize —— 实现可拉伸的div(含限制拉伸的尺寸)
css 拉伸 resize —— 实现可拉伸的div(含限制拉伸的尺寸)
449 1
|
9月前
|
Web App开发 Linux 数据安全/隐私保护
Docker本地部署Firefox火狐浏览器并远程访问
Docker本地部署Firefox火狐浏览器并远程访问
|
1月前
|
Web App开发 安全 前端开发
一个接口4个步骤轻松搞定最新版Chrome、Edge、Firefox浏览器集成ActiveX控件
目前的浏览器市场,谷歌浏览器占据了半壁江山,因此,谷歌也是最有话语权的,2015年开始取消支持 NPAPI 插件,2022 年10月停止支持 PPAPI 插件;而曾经老大哥IE浏览器也已停止服务,退出历史舞台,导致大量曾经安全、便捷的ActiveX控件无法使用。为了解决这个难题,本人特研发出allWebPlugin中间件,重新让所有ActiveX控件能在谷歌、火狐等浏览器使用。
|
7月前
|
Web App开发 Cloud Native 测试技术
云原生之使用Docker部署Firefox浏览器
【7月更文挑战第21天】云原生之使用Docker部署Firefox浏览器
271 3
|
7月前
|
Web App开发 安全 Linux
Linux系统之安装Firefox浏览器
【7月更文挑战第8天】Linux系统之安装Firefox浏览器
391 9

热门文章

最新文章