日期:2014-05-17  浏览次数:20654 次

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

------解决方案--------------------
这是以前帮别人修改的一个,你可以参考一下
<!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>

------解决方案--------------------
HTML code

<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>

------解决方案--------------------
学习
------解决方案--------------------
HTML code


<!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>