建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > div+css > 怎么让父容器自动适应高度

怎么让父容器自动适应高度

时间:2015-06-05 10:42:53  来源:免费模板网 作者:风雪 阅读次数 tagscss兼容

让父容器自动适应高度,有时候上面的浮动影响到你们的浮动那怎么解决这个问题呢,见下面代码
第一种是
 代码如下  
<div id="main" style="display:inline-block;height:auto;background-color:#006699">
<!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=gb2312" />
<title>无标题文档</title>
</head>
<body>
<div id="main" style="background-color:#006699;float:left;">
 <div id="a" style="width:200px; height:300px; background-color:#006666; float:left"></div>
 <div id="b" style="width:700px; height:550px; background-color:#009999;float:left"></div>
</div>
</body>

</html>
 
第二种方法就是clear:bothi清除浮动

 代码如下  
<!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=gb2312" />
<title>无标题文档</title>
</head>
<body>
<div id="main" style="background-color:#006699">
 <div id="a" style="width:200px; height:300px; background-color:#006666; float:left"></div>
 <div id="b" style="width:700px; height:250px; background-color:#009999;float:left"></div>
<div style="clear:both"></div>
</div>
</body>
</html>

本文地址:https://www.freemoban.com/bjrm/2015/0605/2105.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!