CSS HACK 與float浮動實現代碼

來源:互聯網
上載者:User

一、css hack

  以下兩種方法幾乎能解決現今所有hack.
  1, !important
  隨著ie7對!important的支援, !important 方法現在只針對ie6的hack.(注意寫法.記得該聲明位置需要提前.)

 

 代碼如下 複製代碼
<style>
#wrapper
{
width: 100px!important;
width: 80px;
}
</style>
  

2, ie6/ie77對firefox
  *+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" "">

二、float 閉合(清除浮動)

  將以下代碼加入global css 中,給需要閉合的div加上 class="clearfix" 即可,屢試不爽.

 代碼如下 複製代碼
<style>
.clearfix:after
{
content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}
.clearfix
{
display:inline-block;
}
.clearfix {display:block;}
</style>

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.