DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS進階教程
float 閉合(清除浮動)與 CSS HACK 速查
編輯:CSS進階教程     

一、float 閉合(清除浮動)

將以下代碼加入全域 CSS 中,再替需要閉合的 div 加上 class="clearfix" 即可,屢試不爽。

<style>
.clearfix:after
{
content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}
.clearfix
{
display:inline-block;
}
.clearfix {display:block;}
</style>

二、CSS HACK

以下兩種方法幾乎能解決現今絕大多數的 hack 需求。

1. !important:隨著 IE7 開始支援 !important,這個方法如今只用來 hack IE6(務必留意寫法,且該聲明位置需適度提前)。

<style>
#wrapper
{
width: 100px!important;
width: 80px;
}
</style>

2. 針對 IE6/IE7 對 Firefox 的 hack:*+html 與 *html 是 IE 特有的標籤,Firefox 暫不支援,而 *+html 又為 IE7 的專屬標籤。

<style>
#wrapper
{
#wrapper { width: 120px; }
*html #wrapper { width: 80px;}
*+html #wrapper { width: 60px;}
}
</style>

注意:使用 *+html 對 IE7 做 hack 時,必須確保 HTML 頂部有以下聲明:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved