对CSS了解-overflow:hidden

overflow:hidden

列出我在项目中,运用到此属性的例子:

(1)暴力清除浮动

<style type="text/css">
    .wrap {overflow: hidden;zoom:1;background-color: #ccc;}
    .wrap p {float: left;}
</style>
<div class="wrap">
    <p>test of css</p>
</div>

(2)阻止边距外折叠

<style type=”text/css”>
    body,p {padding: 0;margin: 0;}
    .wrap {overflow: hidden;zoom:1;background-color: #ccc;}
    .wrap p {margin-top: 20px;}
</style>

<div class="wrap">
    <p>test of css</p>
</div>

(3)在IE-6,解决定义1px高的块元素

<style type="text/css">
    .line {height: 1px;background-color: #ccc;overflow: hidden;}
</style>   
 
<div class="line"></div>

(4)创建两栏布局

<style type=”text/css”>
    div {height: 500px;}
    .left {float: left;background-color: #000;width: 200px;margin-right: 5px;}
    .right {overflow: hidden;background-color: #ccc;}
</style>

<div class="left"></div>
<div class="right"></div>

标签