常见css hack有三种:1、条件hack,语法“”;2、属性前缀hack,语法“selector{
?属性名:属性值 ?;}”;3、选择器前缀hack,语法“ selector{ 样式代码 }”。
本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。
CSS hack 是通过在 CSS 样式中加入一些特殊的符号,让不同的浏览器识别不同的符号 (什么样的浏览器识别什么样的符号是有标准的,CSS hack 就是让你记住这个标准),,以达到应用不同的 CSS 样式的目的。
CSS hack 是因为现有浏览器对标准的解析不同,为了兼容各浏览器,所采用的一种补救方法.。为了兼容低版本浏览器器的 CSS 解析 BUG,不得不把代码写的很绕, 直接增加了维护成本。
CSS hack 是一种类似作弊的手段, 以欺骗浏览器的方式达到兼容的目的, 是用浏览器的兼容性差异来解决浏览器的兼容性问题。
常用的css hack有三种:条件hack、属性hack、选择符hack
1、条件hack
语法:
<!--[if <keywords>? IE <version>?]> HTML代码块 <![endif]-->
取值:
if条件共包含6种选择方式:是否、大于、大于或等于、小于、小于或等于、非指定版本
- 是否:指定是否IE或IE某个版本。关键字:空
- 大于:选择大于指定版本的IE版本。关键字:gt(greater than)
- 大于或等于:选择大于或等于指定版本的IE版本。关键字:gte(greater than or equal)
- 小于:选择小于指定版本的IE版本。关键字:lt(less than)
- 小于或等于:选择小于或等于指定版本的IE版本。关键字:lte(less than or equal)
非指定版本:选择除指定版本外的所有IE版本。关键字:!
如不想在非IE中看到某区域,可这样写:
<!--[if IE]> <p>你在非IE中将看不到我的身影</p> <![endif]-->
if条件6种选择方式的使用示例
是否,示例代码:
<!--[if IE]> <style> .test{color:red;} </style> <![endif]-->
大于,示例代码:
<!--[if gt IE 6]> <style> .test{color:red;} </style> <![endif]-->
大于或等于,示例代码:
<!--[if gte IE 6]> <style> .test{color:red;} </style> <![endif]-->
小于,示例代码:
<!--[if lt IE 7]> <style> .test{color:red;} </style> <![endif]-->
小于或等于,示例代码:
<!--[if lte IE 7]> <style> .test{color:red;} </style> <![endif]-->
非指定版本,示例代码:
<!--[if ! IE 7]> <style> .test{color:red;} </style> <![endif]-->
2、属性前缀hack
语法:selector{
取值:
_:选择IE6及以下。连接线(中划线)(-)亦可使用,为了避免与某些带中划线的属性混淆,所以使用下划线(_)更为合适。
*:选择IE7及以下。诸如:(+)与(#)之类的均可使用,不过业界对(*)的认知度更高
\9:选择IE6+
\0:选择IE8+和Opera
[;property:value;];:选择webkit核心浏览器(Chrome,Safari)。IE7及以下也能识别。中括号内外的3个分号必须保留,第一个分号前可以是任意规则或任意多个规则[;color:#f00;]; 与 [color:#f00;color:#f00;]; 与 [margin:0;padding:0;color:#f00;]; 是等价的。生效的始终是中括号内的最后一条规则,所以通常选用第一种写法最为简洁。
说明:
选择不同的浏览器及版本
- 尽可能减少对CSS Hack的使用。Hack有风险,使用需谨慎
- 通常如未作特别说明,本文档所有的代码和示例的默认运行环境都为标准模式。
一些CSS Hack由于浏览器存在交叉认识,所以需要通过层层覆盖的方式来实现对不同浏览器进行Hack的。如下面这个例子:
.test{ color:#090\9; /* For IE8+ */ *color:#f00; /* For IE7 and earlier */ _color:#ff0; /* For IE6 and earlier */ }
3、选择器前缀hack
语法:
说明:
选择不同的浏览器及版本
- 尽可能减少对CSS Hack的使用。Hack有风险,使用需谨慎
- 通常如未作特别说明,本文档所有的代码和示例的默认运行环境都为标准模式。
- 一些CSS Hack由于浏览器存在交叉认识,所以需要通过层层覆盖的方式来实现对不同浏览器进行Hack的。
* html .test{color:#090;} /* For IE6 and earlier */ * + html .test{color:#ff0;} /* For IE7 */ .test:lang(zh-cn){color:#f00;} /* For IE8+ and not IE */ .test:nth-child(1){color:#0ff;} /* For IE9+ and not IE */
(学习视频分享:web前端入门)
The above is the detailed content of What are the common css hacks?. For more information, please follow other related articles on the PHP Chinese website!

React'sstrongcommunityandecosystemoffernumerousbenefits:1)ImmediateaccesstosolutionsthroughplatformslikeStackOverflowandGitHub;2)Awealthoflibrariesandtools,suchasUIcomponentlibrarieslikeChakraUI,thatenhancedevelopmentefficiency;3)Diversestatemanageme

React's componentized architecture makes scalable UI development efficient through modularity, reusability and maintainability. 1) Modularity allows the UI to be broken down into components that can be independently developed and tested; 2) Component reusability saves time and maintains consistency in different projects; 3) Maintainability makes problem positioning and updating easier, but components need to be avoided overcomplexity and deep nesting.

TonavigateReact'scomplexecosystemeffectively,understandthetoolsandlibraries,recognizetheirstrengthsandweaknesses,andintegratethemtoenhancedevelopment.StartwithcoreReactconceptsanduseState,thengraduallyintroducemorecomplexsolutionslikeReduxorMobXasnee

Reactuseskeystoefficientlyidentifylistitemsbyprovidingastableidentitytoeachelement.1)KeysallowReacttotrackchangesinlistswithoutre-renderingtheentirelist.2)Chooseuniqueandstablekeys,avoidingarrayindices.3)Correctkeyusagesignificantlyimprovesperformanc

KeysinReactarecrucialforoptimizingtherenderingprocessandmanagingdynamiclistseffectively.Tospotandfixkey-relatedissues:1)Adduniquekeystolistitemstoavoidwarningsandperformanceissues,2)Useuniqueidentifiersfromdatainsteadofindicesforstablekeys,3)Ensureke

React's one-way data binding ensures that data flows from the parent component to the child component. 1) The data flows to a single, and the changes in the state of the parent component can be passed to the child component, but the child component cannot directly affect the state of the parent component. 2) This method improves the predictability of data flows and simplifies debugging and testing. 3) By using controlled components and context, user interaction and inter-component communication can be handled while maintaining a one-way data stream.

KeysinReactarecrucialforefficientDOMupdatesandreconciliation.1)Choosestable,unique,andmeaningfulkeys,likeitemIDs.2)Fornestedlists,useuniquekeysateachlevel.3)Avoidusingarrayindicesorgeneratingkeysdynamicallytopreventperformanceissues.

useState()iscrucialforoptimizingReactappperformanceduetoitsimpactonre-rendersandupdates.Tooptimize:1)UseuseCallbacktomemoizefunctionsandpreventunnecessaryre-renders.2)EmployuseMemoforcachingexpensivecomputations.3)Breakstateintosmallervariablesformor


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.
