CSS HACK 与float浮动实现代码

hack由于不同的浏览器,比如internet explorer 6,internet explorer 7,mozilla firefox等,对css的解析认识不一样,因此会导致生成的页面效果不一样,得不到我们所需要的页面效果。 这个时候我们就需要针对不同的浏览器去写不同的css,让它能够同时兼容不同的浏览器,能在不同的浏览器中也能得到我们想要的页面效果。

一、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>

CSS HACK 与float浮动实现代码

相关文章:

你感兴趣的文章:

标签云: