search
HomeWeb Front-endCSS TutorialHide 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.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Next Level CSS Styling for CursorsNext Level CSS Styling for CursorsApr 23, 2025 am 11:04 AM

Custom cursors with CSS are great, but we can take things to the next level with JavaScript. Using JavaScript, we can transition between cursor states, place dynamic text within the cursor, apply complex animations, and apply filters.

Worlds Collide: Keyframe Collision Detection Using Style QueriesWorlds Collide: Keyframe Collision Detection Using Style QueriesApr 23, 2025 am 10:42 AM

Interactive CSS animations with elements ricocheting off each other seem more plausible in 2025. While it’s unnecessary to implement Pong in CSS, the increasing flexibility and power of CSS reinforce Lee's suspicion that one day it will be a

Using CSS backdrop-filter for UI EffectsUsing CSS backdrop-filter for UI EffectsApr 23, 2025 am 10:20 AM

Tips and tricks on utilizing the CSS backdrop-filter property to style user interfaces. You’ll learn how to layer backdrop filters among multiple elements, and integrate them with other CSS graphical effects to create elaborate designs.

SMIL on?SMIL on?Apr 23, 2025 am 09:57 AM

Well, it turns out that SVG's built-in animation features were never deprecated as planned. Sure, CSS and JavaScript are more than capable of carrying the load, but it's good to know that SMIL is not dead in the water as previously

'Pretty' is in the eye of the beholder'Pretty' is in the eye of the beholderApr 23, 2025 am 09:40 AM

Yay, let's jump for text-wrap: pretty landing in Safari Technology Preview! But beware that it's different from how it works in Chromium browsers.

CSS-Tricks Chronicles XLIIICSS-Tricks Chronicles XLIIIApr 23, 2025 am 09:35 AM

This CSS-Tricks update highlights significant progress in the Almanac, recent podcast appearances, a new CSS counters guide, and the addition of several new authors contributing valuable content.

Tailwind's @apply Feature is Better Than it SoundsTailwind's @apply Feature is Better Than it SoundsApr 23, 2025 am 09:23 AM

Most of the time, people showcase Tailwind's @apply feature with one of Tailwind's single-property utilities (which changes a single CSS declaration). When showcased this way, @apply doesn't sound promising at all. So obvio

Feeling Like I Have No Release: A Journey Towards Sane DeploymentsFeeling Like I Have No Release: A Journey Towards Sane DeploymentsApr 23, 2025 am 09:19 AM

Deploying like an idiot comes down to a mismatch between the tools you use to deploy and the reward in complexity reduced versus complexity added.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.