Hide CSS for browsers: Dugu Nine Swords_Experience exchange
针对浏览器隐藏CSS之独孤九剑
Hide CSS for Browsers
我们都知道浏览器之间是有差异的,很多人在使用XHTML+CSS方式制作网页的时候都曾为此无比头痛。要在这些差异的影响下工作需要很多的技巧,“隐藏CSS”就是其中很重要的一种技巧(甚至是最重要的)。这种技巧的主要思想是,用某些方式对某些浏览器隐藏某些重载的CSS规则。
这篇文章并不是想教你如何使用这种技巧,它面向的是有一定CSS基础的设计开发者,我假定你曾经使用过某种隐藏CSS规则的方法。这里是想把可用的方法与被隐藏规则的浏览器都列出来,方便大家在平时工作时随时查阅。
在这张大表里列出了九种方法,我就称其为“独孤九剑”,希望能帮上你的忙:-D
注:此表格原载 w3development.de。
Browser | @import url("...") | @import url(...) | @import "..." | media="" | @media | comment | attribute | child | Tantek |
---|---|---|---|---|---|---|---|---|---|
Amaya 5.1 Win | x | x | x | x | |||||
IE 3 Win | x | x | x | x | x | x | x | ||
IE 4 Win | x | x | x | x | x | x | x | x | |
IE 5 Win | x | x | x | x | |||||
IE 5.5 Win | x | x | x | ||||||
IE 6 Win | x | x | |||||||
IE 4.01 Mac | x | x | x | x | x | x | |||
IE 4.5 Mac | x | x | x | x | |||||
IE 5 Mac | x | x | x | ||||||
Konqueror 2.1.1 | x | ||||||||
Mozilla 1.0 | |||||||||
Netscape 4.x | x | x | x | x | x | x | x | x | |
Netscape 6.01 | |||||||||
Netscape 6.1 | |||||||||
Netscape 6.2 | |||||||||
Opera 3.60 Win | x | ||||||||
Opera 4.02 Win | |||||||||
Opera 5.02 Win | |||||||||
Opera 5.12 Win | |||||||||
Opera Tech Preview 3 Mac |
My first reaction after reading this list is: Mozilla and Opera are really gods. Only one rule will take effect on the oldest version of Opera, so when we talk about hidden rules later, we basically ignore Mozilla and Opera. The nine "swordsmanship" moves are listed below, with my personally recommended usage occasions also noted next to them. Note that what I recommend may not necessarily match your needs. Please check the table above before using it.
@import url("")
@import url("global.css")
Hide rules for browsers with older versions (version number less than 5).
@import url()
@import url(global.css)
Hidden rules for browsers with older versions of the Windows platform (version number less than 5).
@import ""
@import "global.css"
Hidden rules for browsers with older versions of the Windows platform (version number less than 5).
media=""
<link href="global.css" type="text/css" rel="stylesheet" media="all">
Hide rules for Netscape 4.x.
@media
@media all { ... /* Rules that need to be hidden */ }
If you only consider NN and IE, you will only hide the rules for version 4.x.
comment
#anySelector/* */ { color:#f00; }
This is a precision-guided missile. Only hide rules for IE5 and below. So if you want to define rules separately for IE5 and IE5.5, then rely on it.
attribute
p[id] { color: #0f0; }
Another precision-guided missile. If you don't care about older browsers, you can hide the rules only from IE. For more information about attribute selectors see W3C documentation.
child
p>span { color: #00f; }
Basically the same as above, except that some versions of IE on the Mac platform support this rule.
Tantek
p#tantek { voice-family: "\"}\""; /* Some browsers have parsing bugs */ voice-family: inherit; /* Rules below will be ignored */ color: #f00; }
The famous hidden CSS trick hides rules from all "non-modern" browsers.

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

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

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
