Table of Contents
针对浏览器隐藏CSS之独孤九剑
Hide CSS for Browsers
@import url()
@import ""
@media
comment
attribute
child
Tantek
Home Web Front-end CSS Tutorial Hide CSS for browsers: Dugu Nine Swords_Experience exchange

Hide CSS for browsers: Dugu Nine Swords_Experience exchange

May 16, 2016 pm 12:08 PM

针对浏览器隐藏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 */
}
Copy after login

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;
}
Copy after login

The famous hidden CSS trick hides rules from all "non-modern" browsers.

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;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.

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

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

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

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&#039;s like this.

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

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.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

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

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

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

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

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...

See all articles