设为首页收藏本站关注微信<<< 抵制 IE6 人人有责 >>>
搜索
热搜: 活动 交友 discuz
查看: 2136|回复: 1
打印 上一主题 下一主题

[CSS] div+css中设置了float属性后如何让外层的高度随着内层的高...

[复制链接]
跳转到指定楼层
楼主
发表于 2014-2-21 02:51:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
很多时候,我们在一行多列中运用FLOAT:LEFT OR RIGHT,但是会发现外部层必须要定义高度,而不可以自动调整。经过很长实践摸索:解决方案:在外层使用
  1. overflow:hidden;
复制代码


本帖被以下淘专辑推荐:

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享淘帖1
回复

使用道具 举报

沙发
 楼主| 发表于 2015-9-8 05:36:59 | 只看该作者

今天在用dreamweaver写CSS代码的时候发现在居然给子DIV设置浮动后父DIV的高度自动居然失效,郁闷了半天,只好从google中去寻找答案  ,在google在钻了一下,最终得以解决。

具体效果图如下:

父DIV高度没有自动如下:

父DIV高度自动后效果如下:


html代码如下:

[HTML] 纯文本查看 复制代码
<!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" />
<link href="index.css" type="text/css" rel="stylesheet"/>
<title>无标题文档</title>
</head>

<body>
<div class="header"></div>
<div class="main">
<div class="main1"></div>
<div class="main2"></div>
</div>
<div class="buttom"></div>
</body>
</html>

css代码如下:

没有浮动之前的css代码:

[CSS] 纯文本查看 复制代码
.header{
height:100px;
width:960px;
margin:0px auto;
background:#339933;
}
.main{
min-height:50px;
height:auto;
width:960px;
background:#000000;
margin:0px auto;
}
.main1{
height:300px;
float:left;
width:200px;
background:#CC3366;
}
.main2{
height:300px;
float:left;
width:500px;
background:#CC3366;
margin-left:20px;
}

.buttom{
height:100px;
width:960px;
background:#333300;
margin:0px auto;
}


浮动后的完整代码如下:

[CSS] 纯文本查看 复制代码
.header{
height:100px;
width:960px;
margin:0px auto;
background:#339933;
}
.main{
min-height:50px;
height:auto;
width:960px;
background:#000000;
margin:0px auto;
overflow:auto;
}
.main1{
height:300px;
float:left;
width:200px;
background:#CC3366;
}
.main2{
height:300px;
float:left;
width:500px;
background:#CC3366;
margin-left:20px;
}

.buttom{
height:100px;
width:960px;
background:#333300;
margin:0px auto;
}


总结:其实很简单 只需要在父DIV中加入overflow:auto或overflow: hidden这个属性就搞定。哈哈 是不是很简单呀。


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?免费注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

QQ|手机版|Archiver|源于生活(个人生活娱乐工作的笔记)css3,html5,学习笔记    

GMT+8, 2024-4-29 01:29 , Processed in 0.062400 second(s), 29 queries .

Powered by Mr.Kevin-ying

© 2004-2015

快速回复 返回顶部 返回列表