站长论坛

标题: 发一个DIV+CSS高度自适应方法网页代码实例 [打印本页]

作者: superadmin    时间: 2008-9-23 21:05
标题: 发一个DIV+CSS高度自适应方法网页代码实例
我今天晚上,做一个快印公司的网站布局,在Div镶套布局中,父标签DIV的高度不变。在IE下没有问题,但是在FIREFOX下就有问题了。
如图:发了两张同样的怕百度盗链,另一张放在我网站上,在教育网内


代码:
<!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>
</head>
<body>
<div style="width:300px;border:#FF0000 solid 1px;">
  <div style="width:200px; float:left; position:relative;border:#000000 solid 1px; clear:left">
    <p>此处显示</p>
    <p>新 Div 标签的</p>
    <p>内容</p>
  </div>
  <div style="width:80px; float:left; position:relative;border:#0000CC solid 1px; clear:right">此处显示新 Div 标签的内容</div>
</div>
</body>
</html>
在网上搜索一下发现有同样问题的人还挺多,给的方法也很多,有用JS的,有用HEIGHT=100%的,我感觉都没有作用。

我在下面加了一个
<div style="clear:both"></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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<div style="width:300px;border:#FF0000 solid 1px;">
  <div style="width:200px; float:left; position:relative;border:#000000 solid 1px; clear:left">
    <p>此处显示</p>
    <p>新 Div 标签的</p>
    <p>内容</p>
  </div>
  <div style="width:80px; float:left; position:relative;border:#0000CC solid 1px; clear:right">此处显示新 Div 标签的内容</div>
  <div style="clear:both"></div>
</div>
</body>
</html>
这样就可以解决问题了。




欢迎光临 站长论坛 (http://tzlink.com/bbs/) Powered by Discuz! X3.2