惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
I
InfoQ
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
美团技术团队
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
Last Week in AI
Last Week in AI
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
G
Google Developers Blog
博客园 - 叶小钗
博客园 - Franky

博客园 - kenty

“与”运算是什么意思 VSS 服务器端,客户端的配置 C#:GridView导出Excel,以及runat=server错误处理方法 MANIFEST.MF的用途(转载) 根据绑定的值的不同改变gridview里某一单元格的字体或背景颜色 Response.Write()语句造成页面布局改变以及字体变化的解决办法 已经有2年没有接触代码了!重新回归,做个纪念吧! 关于忘记MySQL的root用户密码的问题 利用JDK1.5的工具对远程的Java应用程序进行监测(摘录) Visualvm 远程测试 问题 - kenty MYOB 的一些开发资料 连接MYOB ODBC,在MyEclipse 下Commit成功,在Tomcat下单独运行,Commit显示Connection 已经关闭 MYOB Developer Jave 创建连接 tomcat dbcp jndi 配置 JAVA 事务处理 jsp中文件下载的实现 - kenty - 博客园 META Header - kenty - 博客园 Proxy server 緩存 jsp html Putty对数据库进行备份及恢复
css+div自动适应高度,在IE和firefox下都能适应 (左右DIV自适...
kenty · 2012-11-16 · via 博客园 - kenty

网上找了些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

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