Hide CSS_CSS/HTML from browsers
我们都知道浏览器之间是有差异的,很多人在使用XHTML+CSS方式制作网页的时候都曾为此无比头痛。要在这些差异的影响下工作需要很多的技巧,“隐藏CSS”就是其中很重要的一种技巧(甚至是最重要的)。这种技巧的主要思想是,用某些方式对某些浏览器隐藏某些重载的CSS规则。
这篇文章并不是想教你如何使用这种技巧,它面向的是有一定CSS基础的设计开发者,我假定你曾经使用过某种隐藏CSS规则的方法。这里是想把可用的方法与被隐藏规则的浏览器都列出来,方便大家在平时工作时随时查阅。
在这张大表里列出了九种方法,我就称其为“独孤九剑”,希望能帮上你的忙:-D
注:此表格原载 w3development.de。

看完這張表之後我的第一個反應是:Mozilla和Opera真乃神人也。只有一條規則會對Opera最老的一個版本起作用,所以後面我們在講到隱藏規則的時候基本上就不考慮Mozilla和Opera了。以下列出這九種「劍法」的招數,同時在旁邊也注上了我個人推薦的使用場合。注意,我推薦的不一定與你的需求相符,使用前請對照上面的表格。
@import url("")
<span lang="en" style="FONT-SIZE: 12pt">@import url("global.css")<code><span lang="en" style="FONT-SIZE: 12pt">@import url("global.css")</span>
對舊版(版號小於5)的瀏覽器隱藏規則。
@import url()
<span lang="en" style="FONT-SIZE: 12pt">@import url(global.css)<code><span lang="en" style="FONT-SIZE: 12pt">@import url(global.css)</span>
對Windows平台的舊版本(版號小於5)瀏覽器隱藏規則。
@import ""
<span lang="en" style="FONT-SIZE: 12pt">@import "global.css"<code><span lang="en" style="FONT-SIZE: 12pt">@import "global.css"</span>
對Windows平台的舊版本(版號小於5)瀏覽器隱藏規則。
media=""
<span lang="en" style="FONT-SIZE: 12pt"><link href="global.css" type="text/css" rel="stylesheet" media="all">
<code><span lang="en" style="FONT-SIZE: 12pt"><link href="global.css" type="text/css" rel="stylesheet" media="all"/></span>
對Netscape 4.x隱藏規則。
@media
1 |
|
1 |
|
1 |
|
如果只考慮NN和IE的話就是只對4.x版本隱藏規則。
comment
<span lang="en" style="FONT-SIZE: 12pt">#anySelector/* */ { color:#f00; }<code><span lang="en" style="FONT-SIZE: 12pt">#anySelector/* */ { color:#f00; }</span>
這可是精確導引飛彈。只對IE5及以下版本隱藏規則。所以如果要把IE5和IE5.5分開定義規則,那就靠它了。
attribute
<span lang="en" style="FONT-SIZE: 12pt">p[id] { color: #<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="0" unitname="F">0f</chmetcnv>0; }<code><span lang="en" style="FONT-SIZE: 12pt">p[id] { color: #<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="0" unitname="F">0f</chmetcnv>0; }</span>
又一精確導引飛彈。如果不關心舊版瀏覽器,那就是只對IE隱藏規則。關於屬性選擇器的更多資訊請看W3C的文件。
child
<span lang="en" style="FONT-SIZE: 12pt">p>span { color: #<chmetcnv w:st="on" tcsc="0" numbertype="1" negative=" False" hasspace="False" sourcevalue="0" unitname="F">00f</chmetcnv>; }<code><span lang="en" style="FONT-SIZE: 12pt">p>span { color: #<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="0" unitname="F">00f</chmetcnv>; }</span>
基本同上,只是Mac平台部分版本的IE支援這個規則。
Tantek
1 |
|
1 |
|
1 |
|
1 |
|
1 |
|
著名的隱藏CSS技巧,對所有「非現代」瀏覽器隱藏規則

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











Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

In this week's roundup of platform news, Chrome introduces a new attribute for loading, accessibility specifications for web developers, and the BBC moves

This is me looking at the HTML element for the first time. I've been aware of it for a while, but haven't taken it for a spin yet. It has some pretty cool and

Buy or build is a classic debate in technology. Building things yourself might feel less expensive because there is no line item on your credit card bill, but

In this week's roundup, a handy bookmarklet for inspecting typography, using await to tinker with how JavaScript modules import one another, plus Facebook's

For a while, iTunes was the big dog in podcasting, so if you linked "Subscribe to Podcast" to like:

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used
