


CSS-HACK writing methods for mainstream browsers and IE common condition comments
本文将为你总结CSS针对各浏览器的兼容HACK(以IE6/IE7/IE8 /FF为主),以及IE特有的条件注释使用方法.
对于前端工作者,最痛苦的事莫过于浏览器兼容性的调试,而这最痛苦的事中,最变态的莫过于微软的三个版本IE6.0/IE7.0/IE8.0. 为了让所写代码在各主流浏览器中正常运行,我们不得不为各种浏览器写对应的样式。本文,青鸟将为你总结CSS针对各浏览器的兼容HACK(以IE6/IE7/IE8 /FF为主),以及IE特有的条件注释使用方法.
一、通用区分方式:
IE6、IE7能识别*,标准浏览器(如FF)不能识别*;
IE6能识别*,但不能识别 !important;
IE7能识别*,也能识别 !important;
IE8能识别\0,不能识别*,+,_,* 加!important;
FF不能识别*,但能识别 !important;
例如style=”*width:10px!important; width:20px;”,其在IE7下宽度为10px,在IE6下宽度是20px.
其中还有如下三种写法:
第一种
width:100px; /* FireFox及其他浏览器 */ width:200px\0; /* IE8能识别\0*/ *width:300px!important; /* ,IE7 既能能识别*号,也能识别important */ *width:400px; /* IE6也能识别*号 */ /*Mr.Think提示:请注意书写顺序@MrThink.net*/
第二种
width:100px; /* FireFox及其他浏览器 */ width:200px\0; /* IE8能识别\0*/ *width:300px; /* IE7也能识别*号 */ _width:400px; /* IE6能识别下划线*/ /*Mr.Think提示:请注意书写顺序@MrThink.net*/
第三种
width:100px; /* FireFox及其他浏览器 */ width:200px\0; /* IE8能识别\0*/ +width:300px; /* +只识别IE7 */ _width:400px; /* IE6能识别下划线*/ /*Mr.Think提示:请注意书写顺序@MrThink.net*/
二、不常见的HACK(OP表示Opera,SA表示Safari),其中第3条比较实用
1..color1{ color:#F00; color/*\**/:#00F /*\**/}/*IE6,IE7,IE8,FF,OP,SA识别*/ 2..color2{ color:#F00; color /*\**/:#00F /*\9**/}/*IE7,IE8,FF,OP,SA识别*/ 3..color3{ color:#F00; color/*\**/:#00F \9}/*IE6,IE7,IE8识别*/ 4..color4{ color:#F00; color /*\**/:#00F\9}/*IE7,IE8识别*//*“color”和“/*\**/”之间有个空格*/
三、各种浏览器独立支持的hack
width:100px\0;/* 支持IE8 */ _width:100px; /* 支持IE6 */ [width:100px; /* 支持IE6,7 */ +width:100px; /* 支持IE6,7 */ *width:100px; /* 支持IE6,7 */ *width:100px!important; /* 支持IE6,7, */ *+width:100px; /* 支持IE6,7, */ *+width:100px!important;/* 支持IE6,7, */ width:100px\9; /* 支持IE6,7,8 */ width:100px!important; /* 支持IE6,7,8,FF */ w\idth:100px; /*IE5.x不支持 IE6、IE7、IE8、FF支持 */
四、IE特有的html条件注释使用规则
1.仅IE可见的写法
5.非IE可见的写法(注意:此条不符合WEB标准,但的确实用)
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
CSS3中的Transition过度与Animation动画属性的使用介绍
The above is the detailed content of CSS-HACK writing methods for mainstream browsers and IE common condition comments. For more information, please follow other related articles on the PHP Chinese website!

I know, I know: there are a ton of content management system options available, and while I've tested several, none have really been the one, y'know? Weird pricing models, difficult customization, some even end up becoming a whole &

Linking CSS files to HTML can be achieved by using elements in part of HTML. 1) Use tags to link local CSS files. 2) Multiple CSS files can be implemented by adding multiple tags. 3) External CSS files use absolute URL links, such as. 4) Ensure the correct use of file paths and CSS file loading order, and optimize performance can use CSS preprocessor to merge files.

Choosing Flexbox or Grid depends on the layout requirements: 1) Flexbox is suitable for one-dimensional layouts, such as navigation bar; 2) Grid is suitable for two-dimensional layouts, such as magazine layouts. The two can be used in the project to improve the layout effect.

The best way to include CSS files is to use tags to introduce external CSS files in the HTML part. 1. Use tags to introduce external CSS files, such as. 2. For small adjustments, inline CSS can be used, but should be used with caution. 3. Large projects can use CSS preprocessors such as Sass or Less to import other CSS files through @import. 4. For performance, CSS files should be merged and CDN should be used, and compressed using tools such as CSSNano.

Yes,youshouldlearnbothFlexboxandGrid.1)Flexboxisidealforone-dimensional,flexiblelayoutslikenavigationmenus.2)Gridexcelsintwo-dimensional,complexdesignssuchasmagazinelayouts.3)Combiningbothenhanceslayoutflexibilityandresponsiveness,allowingforstructur

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools
