如何清除我的浮标? [英] How do I clear my floats?

查看:105
本文介绍了如何清除我的浮标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!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" lang="en-US">
<head>
<style type="text/css">
body {width:100%;overflow-x:hidden;}
*{margin:0; padding:0; border:0;}
.wrap{float:left;width:100%;background-color:#ccc;}
.content{width:1000px;margin:0 auto;background-color:#efefef;}
.left{float:left;width:760px;}
.right{float:left;width:240px;}
</style>
</head>
<body>
<div class="wrap">
    <div class="content">
        <div class="left">
            111<br />
            222<br />
            <!-- there still have some lines -->
        </div>
        <div class="right">         
        </div>
    </div>
</div>
</body>
</html>

DIV高度为零,背景颜色已消失。即使我给 DIV.content height auto或100%。为什么背景颜色消失?

The DIV height is zero, the background color has disappeared. Even if I give DIV.content height auto or 100%. Why is the background color gone?

推荐答案

添加 overflow:auto .content 清除浮动

示例: http://jsbin.com/onedi3

有关清除的详细信息,请访问 http://www.quirksmode.org/css/clearing.html

More information for clearing you can find at http://www.quirksmode.org/css/clearing.html

这篇关于如何清除我的浮标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆