展会信息港展会大全

CSS HACK 与float浮动实现代码
来源:互联网   发布日期:2016-03-25 15:55:23   浏览:1231次  

导读:CSS hack由于不同的浏览器,比如Internet Explorer 6,Internet Explorer 7,Mozilla Firefox等,对CSS的解析认识不一样,因此会导致生成的页...

CSS hack由于不同的浏览器,比如Internet Explorer 6,Internet Explorer 7,Mozilla Firefox等,对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>

赞助本站

人工智能实验室

相关热词: 开发 编程 android

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港