css hacks (ie6,ie7,ie8,firefox,Chrome)
分类:Web前端
IE6能识别下划线"_"和星号" * ",IE7能识别星号" * ",但不能识别下划线"_", IE8能识别" \9",但不能识别下划线"_", 而firefox两个都不能认识,却可以识别‘!important’。等等
书写顺序,一般是将识别能力强的浏览器的CSS写在后面。下面列举常用的CSS hack方法
1:!important
!important作用是提高指定样式规则的应用优先权。
IE7以及所有标准浏览器能识别!important
区别IE6与IE7与其他浏览器
.browserTest
{
border:20px solid #60A179 !important;
border:20px solid #00F;
}
在Mozilla中或者IE7浏览时候,能够理解!important的优先级,因此显示#60A179的颜色:
在IE6中浏览时候,不能够理解!important的优先级,因此显示#00F的颜色:
2:*
IE都能识别*;标准浏览器(如火狐)不能识别*
区别IE6与火狐
.browserTest
{
border:20px solid #60A179;
*border:20px solid #00F;
}
区别IE7与火狐
.browserTest
{
border:20px solid #60A179;
*border:20px solid #00F;
}
区别IE7,IE6与火狐
.browserTest
{
border:20px solid #60A179;
*border:20px solid #00F !important;
*border:20px solid ###;
}
3:_
IE6支持下划线,IE7和firefox均不支持下划线
区别IE7,IE6与火狐
.browserTest
{
border:20px solid #60A179;
*border:20px solid #00F;
_border:20px solid ###;
}
/*不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面*/
4:*+html 与 *html
*+html 与 *html 是IE特有的标签, firefox 暂不支持.而*+html 又为 IE7特有标签
.browserTest { width: 120px; } /* FireFox fixed */
*html .browserTest { width: 80px;} /* ie6 fixed */
*+html .browserTest { width: 60px;} /* ie7 fixed */
5:\9 专属IE8的Hack
.browserTest { width: 120px\9; } /* IE8 fixed */
6:Chrome
@media screen and (-webkit-min-device-pixel-ratio:0) {
/* 针对 Google Chrome、Safari 3.0、Opera 9 的CSS样式 */
}
@media screen and (-webki
相关文档:
僞类 意义
:first-child 第一个孩子元素
:first-line&nb ......
In this specification, the expression collapsing margins means that adjoining margins (no non-empty content, padding or border areas or clearance separate them) of two or more boxes (which may be next to one another or nested) combine to form a single margin.
In CSS 2.1, horizontal margins ne ......
网页设计DIV+CSS元素解析,<head>部分前:
(一) DOCTYPE 和DTD
用DW新建网页时,总会生成一句
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
这句是DOCTYPE声明,DOCTY ......
一 css的优先级
今天有人跟我说css
hack中用!important来区分ie6,因为ie6不支持!important,是的在很早以前我也是用过这种方法写hack,但是后来就基本不用了。本来我对他谁的ie6不支持!important也没什么异议,可是正好在前几天正好用个这个!important属性解决了一个样式优先级的问题,而且是支持ie6的,这是为什么呢? ......