---
title: "解决浮动元素父容器高度自适应问题"
author: "accphc"
date: "2014-04-11T16:53:43Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2014-04-11T16:53:43Z"
id: 2043853
url: "https://hc24.iteye.com/blog/2043853"
---

```
<!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>clearfix</title> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<meta http-equiv="Content-Language" content="zh-CN" /> 
<style type="text/css"> 
.area{background:#ccc;width:960px;}/*定义父容器背景颜色，以便于观察；定义宽度，使其在IE下高度自适应*/
.clearfix:after{height:0px;visibility:hidden;content:".";clear:both;display:block;}
.fl{float:left;background:#FFDF00;}
</style> 
</head> 
<body> 
<div class="area clearfix">
    <div class="fl">floater</div>
</div>
</body> 
</html>
```

## [](http://www.cnblogs.com/eecc/archive/2011/10/23/2221717.html)