


CSS-HACK writing methods for mainstream browsers and IE common condition comments
Jul 02, 2018 am 10:04 AM本文將為你總結(jié)CSS針對(duì)各瀏覽器的兼容HACK(以IE6/IE7/IE8 /FF為主),以及IE特有的條件注釋使用方法.
對(duì)于前端工作者,最痛苦的事莫過于瀏覽器兼容性的調(diào)試,而這最痛苦的事中,最變態(tài)的莫過于微軟的三個(gè)版本IE6.0/IE7.0/IE8.0. 為了讓所寫代碼在各主流瀏覽器中正常運(yùn)行,我們不得不為各種瀏覽器寫對(duì)應(yīng)的樣式。本文,青鳥將為你總結(jié)CSS針對(duì)各瀏覽器的兼容HACK(以IE6/IE7/IE8 /FF為主),以及IE特有的條件注釋使用方法.
一、通用區(qū)分方式:
IE6、IE7能識(shí)別*,標(biāo)準(zhǔn)瀏覽器(如FF)不能識(shí)別*;
IE6能識(shí)別*,但不能識(shí)別 !important;
IE7能識(shí)別*,也能識(shí)別 !important;
IE8能識(shí)別\0,不能識(shí)別*,+,_,* 加!important;
FF不能識(shí)別*,但能識(shí)別 !important;
例如style=”*width:10px!important; width:20px;”,其在IE7下寬度為10px,在IE6下寬度是20px.
其中還有如下三種寫法:
第一種
width:100px; /* FireFox及其他瀏覽器 */ width:200px\0; /* IE8能識(shí)別\0*/ *width:300px!important; /* ,IE7 既能能識(shí)別*號(hào),也能識(shí)別important */ *width:400px; /* IE6也能識(shí)別*號(hào) */ /*Mr.Think提示:請(qǐng)注意書寫順序@MrThink.net*/
第二種
width:100px; /* FireFox及其他瀏覽器 */ width:200px\0; /* IE8能識(shí)別\0*/ *width:300px; /* IE7也能識(shí)別*號(hào) */ _width:400px; /* IE6能識(shí)別下劃線*/ /*Mr.Think提示:請(qǐng)注意書寫順序@MrThink.net*/
第三種
width:100px; /* FireFox及其他瀏覽器 */ width:200px\0; /* IE8能識(shí)別\0*/ +width:300px; /* +只識(shí)別IE7 */ _width:400px; /* IE6能識(shí)別下劃線*/ /*Mr.Think提示:請(qǐng)注意書寫順序@MrThink.net*/
二、不常見的HACK(OP表示Opera,SA表示Safari),其中第3條比較實(shí)用
1..color1{ color:#F00; color/*\**/:#00F /*\**/}/*IE6,IE7,IE8,FF,OP,SA識(shí)別*/ 2..color2{ color:#F00; color /*\**/:#00F /*\9**/}/*IE7,IE8,FF,OP,SA識(shí)別*/ 3..color3{ color:#F00; color/*\**/:#00F \9}/*IE6,IE7,IE8識(shí)別*/ 4..color4{ color:#F00; color /*\**/:#00F\9}/*IE7,IE8識(shí)別*//*“color”和“/*\**/”之間有個(gè)空格*/
三、各種瀏覽器獨(dú)立支持的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條件注釋使用規(guī)則
1.僅IE可見的寫法
5.非IE可見的寫法(注意:此條不符合WEB標(biāo)準(zhǔn),但的確實(shí)用)
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,更多相關(guān)內(nèi)容請(qǐng)關(guān)注PHP中文網(wǎng)!
相關(guān)推薦:?
關(guān)于CSS編程的OOCSS和SMACSS設(shè)計(jì)模式的介紹
CSS3中的Transition過度與Animation動(dòng)畫屬性的使用介紹
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!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

CSS blocks page rendering because browsers view inline and external CSS as key resources by default, especially with imported stylesheets, header large amounts of inline CSS, and unoptimized media query styles. 1. Extract critical CSS and embed it into HTML; 2. Delay loading non-critical CSS through JavaScript; 3. Use media attributes to optimize loading such as print styles; 4. Compress and merge CSS to reduce requests. It is recommended to use tools to extract key CSS, combine rel="preload" asynchronous loading, and use media delayed loading reasonably to avoid excessive splitting and complex script control.

Autoprefixer is a tool that automatically adds vendor prefixes to CSS attributes based on the target browser scope. 1. It solves the problem of manually maintaining prefixes with errors; 2. Work through the PostCSS plug-in form, parse CSS, analyze attributes that need to be prefixed, and generate code according to configuration; 3. The usage steps include installing plug-ins, setting browserslist, and enabling them in the build process; 4. Notes include not manually adding prefixes, keeping configuration updates, prefixes not all attributes, and it is recommended to use them with the preprocessor.

AnimatingSVGwithCSSispossibleusingkeyframesforbasicanimationsandtransitionsforinteractiveeffects.1.Use@keyframestodefineanimationstagesforpropertieslikescale,opacity,andcolor.2.ApplytheanimationtoSVGelementssuchas,,orviaCSSclasses.3.Forhoverorstate-b

Theconic-gradient()functioninCSScreatescirculargradientsthatrotatecolorstopsaroundacentralpoint.1.Itisidealforpiecharts,progressindicators,colorwheels,anddecorativebackgrounds.2.Itworksbydefiningcolorstopsatspecificangles,optionallystartingfromadefin

The scope of CSS custom properties depends on the context of their declaration, global variables are usually defined in :root, while local variables are defined within a specific selector for componentization and isolation of styles. For example, variables defined in the .card class are only available for elements that match the class and their children. Best practices include: 1. Use: root to define global variables such as topic color; 2. Define local variables inside the component to implement encapsulation; 3. Avoid repeatedly declaring the same variable; 4. Pay attention to the coverage problems that may be caused by selector specificity. Additionally, CSS variables are case sensitive and should be defined before use to avoid errors. If the variable is undefined or the reference fails, the fallback value or default value initial will be used. Debug can be done through the browser developer

Mobile-firstCSSdesignrequiressettingtheviewportmetatag,usingrelativeunits,stylingfromsmallscreensup,optimizingtypographyandtouchtargets.First,addtocontrolscaling.Second,use%,em,orreminsteadofpixelsforflexiblelayouts.Third,writebasestylesformobile,the

CSS's :target pseudo-class is used to style the target element based on the URL fragment identifier. It works by the browser scrolling to the element when the URL contains a # symbol and element id and allows a specific style to be applied to the element via :target. Common use cases include highlighting the page section after navigation, creating tabs or slideshows without JavaScript, and improving accessibility to long pages. Usage tips include ensuring that id is unique, combining transition or animation effects, switching content visibility with display attributes, and considering compatibility with older browsers.

There are three ways to create a CSS loading rotator: 1. Use the basic rotator of borders to achieve simple animation through HTML and CSS; 2. Use a custom rotator of multiple points to achieve the jump effect through different delay times; 3. Add a rotator in the button and switch classes through JavaScript to display the loading status. Each approach emphasizes the importance of design details such as color, size, accessibility and performance optimization to enhance the user experience.
