列出我在項目中,運用到此屬性的例子:
(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;zoom:1;background-color: #ccc;}
</style>
<div class="left"></div>
<div class="right"></div>