优先级

important > 内联(1,0,0,0) > id(1,0,0) > class(1,0) > element(1) > *通配符

css引入方式

方式一:在head里用link标签(推荐使用)
<link rel="stylesheet" href="xxx.css"> 方式二:在head里用style标签
<style> some css </style> 方式三:内联,在标签上用style
<div style=" some css "></div> 方式四:@import
@import url("xxx.css"); link和@import的区别:
1.兼容性:@import在IE5+支持,link全部支持
2.DOM样式操作:link(可被js改变),@import(不可被js改变)
3.加载顺序:@import必须放在最顶部,和link混用时破坏并行加载,link阻断@import,多个@import不同于预期加载顺序

Hacks

转自:梦想天空

IE选择器 Hack

/* IE 6 and below */
* html .selector {}
.suckyie6.selector {} /* .suckyie6 can be any unused class */ /* IE 7 and below */
.selector, {} /* IE 7 */
*:first-child+html .selector {}
.selector, x:-IE7 {}
*+html .selector {} /* Everything but IE 6 */
html > body .selector {} /* Everything but IE 6/7 */
html > /**/ body .selector {}
head ~ /* */ body .selector {} /* Everything but IE 6/7/8 */
:root *> .selector {}
body:last-child .selector {}
body:nth-of-type(1) .selector {}
body:first-of-type .selector {}

IE属性/值 Hack

/* IE 6 */
.selector { _color: blue; }
.selector { -color: blue; } /* IE 6/7 - acts as an !important */
.selector { color: blue !ie; }
/* string after ! can be anything */ /* IE 6/7 - any combination of these characters:
! $ & * ( ) = % + @ , . / ` [ ] # ~ ? : < > | */
.selector { !color: blue; }
.selector { $color: blue; }
.selector { &color: blue; }
.selector { *color: blue; }
/* ... */ /* IE 8/9 */
.selector { color: blue\0/; }
/* must go at the END of all rules */ /* IE 8/9 */
.selector { color: blue\0/; }
/* must go at the END of all rules */ /* IE 9/10 */
.selector:nth-of-type(1n) { color: blue\9; } /* IE 6/7/8/9/10 */
.selector { color: blue\9; }
.selector { color/*\**/: blue\9; } /* Everything but IE 6 */
.selector { color/**/: blue; }

IE Media Query Hack

/* IE 6/7 */
@media screen\9 {} /* IE 8 */
@media \0screen {} /* IE 9/10, Firefox 3.5+, Opera */
@media screen and (min-resolution: +72dpi) {} /* IE 10+ */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {} /* IE 6/7/8 */
@media \0screen\,screen\9 {} /* IE 8/9/10 & Opera */
@media screen\0 {} /* IE 9/10 */
@media screen and (min-width:0\0) {} /* Everything but IE 6/7/8 */
@media screen and (min-width: 400px) {}

IE Javascript Hack

/* IE 6 */
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 6]><i></i><![endif]-->";
var isIE = checkIE.getElementsByTagName("i").length == 1; /* IE 7 */
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 7]><i></i><![endif]-->";
var isIE = checkIE.getElementsByTagName("i").length == 1;
navigator.appVersion.indexOf("MSIE 7.")!=-1 /* IE <= 8 */
var isIE = '\v'=='v'; /* IE 8 */
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 8]><i></i><![endif]-->";
var isIE = checkIE.getElementsByTagName("i").length == 1; /* IE 9 */
(checkIE = document.createElement("b")).innerHTML = "<!--[if IE 9]><i></i><![endif]-->";
var isIE = checkIE.getElementsByTagName("i").length == 1; /* IE 10 */
var isIE = eval("/*@cc_on!@*/false") && document.documentMode === 10; /* IE 10 */
var isIE = document.body.style.msTouchAction != undefined;

Firefox 浏览器

选择器Hack

/* Firefox 1.5 */
body:empty .selector {} /* Firefox 2+ */
.selector, x:-moz-any-link {} /* Firefox 3+ */
.selector, x:-moz-any-link; x:default {} /* Firefox 3.5+ */
body:not(:-moz-handler-blocked) .selector {} 媒体查询 Hack /* Firefox 3.5+, IE 9/10, Opera */
@media screen and (min-resolution: +72dpi) {} /* Firefox 3.6+ */
@media screen and (-moz-images-in-menus:0) {} /* Firefox 4+ */
@media screen and (min--moz-device-pixel-ratio:0) {} Javascript Hack /* Firefox */
var isFF = !!navigator.userAgent.match(/firefox/i); /* Firefox 2 - 13 */
var isFF = Boolean(window.globalStorage); /* Firefox 2/3 */
var isFF = /a/[-1]=='a'; /* Firefox 3 */
var isFF = (function x(){})[-5]=='x';

Chrome浏览器

选择器 Hack

/* Chrome 24- and Safari 5- */
::made-up-pseudo-element, .selector {} 媒体查询 Hack /* Chrome, Safari 3+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {} Javascript Hack /* Chrome */
var isChrome = Boolean(window.chrome);

Safari浏览器

选择器Hack

/* Safari 2/3 */
html[xmlns*=""] body:last-child .selector {}
html[xmlns*=""]:root .selector {} /* Safari 2/3.1, Opera 9.25 */
*|html[xmlns*=""] .selector {} /* Safari 5- and Chrome 24- */
::made-up-pseudo-element, .selector {} 媒体查询Hack /* Safari 3+, Chrome */
@media screen and (-webkit-min-device-pixel-ratio:0) {} Javascript Hack /* Safari */
var isSafari = /a/.__proto__=='//';

Opera浏览器

选择器Hack

/* Opera 9.25, Safari 2/3.1 */
*|html[xmlns*=""] .selector {} /* Opera 9.27 and below, Safari 2 */
html:first-child .selector {} /* Opera 9.5+ */
noindex:-o-prefocus, .selector {} 媒体查询Hack /* Opera 7 */
@media all and (min-width: 0px){} /* Opera 12- */
@media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) {} /* Opera, Firefox 3.5+, IE 9/10 */
@media screen and (min-resolution: +72dpi) {} /* Opera, IE 8/9/10 */
@media screen {} Javascript Hack /* Opera 9.64- */
var isOpera = /^function \(/.test([].sort); /* Opera 12- */
var isOpera = Boolean(window.opera);    

CSS优先级、引入方式、Hack的更多相关文章

  1. python 全栈开发,Day46(列表标签,表格标签,表单标签,css的引入方式,css选择器)

    一.列表标签 列表标签分为三种. 1.无序列表<ul>,无序列表中的每一项是<li> 英文单词解释如下: ul:unordered list,“无序列表”的意思. li:lis ...

  2. 前端1-----CSS层叠样式表了解,css的引入方式,三大选择器(标签,类,id),高级选择器

    前端1-----CSS层叠样式表了解,css的引入方式,三大选择器(标签,类,id),高级选择器 一丶CSS简介    叠样式表(英文全称:Cascading Style Sheets)是一种用来表现 ...

  3. Day46(列表标签,表格标签,表单标签,css的引入方式,css选择器)

    一.列表标签 列表标签分为三种. 1.无序列表<ul>,无序列表中的每一项是<li> 英文单词解释如下: ul:unordered list,“无序列表”的意思. li:lis ...

  4. 前端(二)—— CSS的引入方式、长度与颜色单位、常用样式、选择器

    CSS的引入方式.长度与颜色单位.常用样式.选择器 一.CSS的三种引入方式 1.行间式 <!doctype html> <html> <head> <met ...

  5. CSS的引入方式

    再用HTML编写的文本中,有是没能达到我们想要的效果,此时此刻我们可以用过引用CSS来控制!这不仅使得效果好而且代码层次清晰.CSS的引入方式可以分为四类: 1.链入外部样式表,就是把样式表保存为一个 ...

  6. CSS的引入方式和样式

    CSS的引入方式和样式 一.样式 行内样式 内接样式 外接样式(1.链接式 2.导入式) <!--行内样式--> <div> <p style="color: ...

  7. CSS的引入方式和复合选择器

    CSS的引入方式 样式表 优点 缺点 范围 行内样式表 书写方便 结构样式混写 控制一个标签 内部样式表 部分结构和样式相分离 没有彻底 控制一个页面 外部样式表 完全实现结构和样式分离 需要引入 控 ...

  8. css样式引入方式,及常用设置标签样式

    一. 三种样式引入方式   1. 内联式-直接写在div标签中,不推荐用 <div style="color:red;font-size:20px;font-family:'Micro ...

  9. CSS 从入门到放弃系列:CSS的引入方式

    css的四种引入方式 内联方式(行间样式) <div style="width:100px;height: 100px; background-color: red"> ...

  10. 5.CSS的引入方式

    CSS的三种样式表 按照CSS样式书写的位置(或者引入的方式),CSS的样式表可以分为三大类: 1.行内样式表(行内式) <div style="color:red: font-siz ...

随机推荐

  1. 遗传算法matlab实现

    我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang 以下运用MATLAB实现遗传算法:   clc clear   %参数 a = 0 ; b = 4 ; e ...

  2. 设置iOS项目BuildVersion自动增加-备用

    一.概念阐述:Build与Version的区别 在iOS中有两种“版本号”,也就是所谓的version号与build号,如下图所示: 我们用最简洁的语言来区分这两个版本号的区别以及用途如下: Vers ...

  3. JQuery的插件

    最近需要修改ftl文件,使用一般的freemarker插件不能有效处理里边的部分JQuery内容,所以特地下载了一个Spket插件, 地址为 http://www.agpad.com/update 再 ...

  4. 工控主板EM9161对ISO7816协议的支持

    在当前的金融POS终端及相关领域,ISO7816通讯协议得到了广泛应用.英创的工控主板EM9161,可在其异步串口的基础上,通过简单的设置,就可把串口转为符合ISO7816协议的接口,实现与各种智能卡 ...

  5. linq 跨库查询

    可以用多个DBContext,例如有DBContext1和DBContext2,但是不能将两个DBContext用在同一个查询中,可以分开,先用一个查出结果集1,再在第二个查询中使用结果集1就可以了

  6. linux网络配置相关文件

    网络接口(interface)是网络硬件设备在操作系统中的表示方法,比如网卡在Linux操作系统中用ethX,是由0开始的正整数,比如eth0.eth1...... ethX.而普通猫和ADSL的接口 ...

  7. myeclipse实现Servlet实例(3) 通过继承HttpServlet接口实现

    (1) 在软件公司 90%都是通过该方法开发. //在HttpServlet 中,设计者对post 提交和 get提交分别处理   //回忆 <form action="提交给?&qu ...

  8. c语言编程之sglib库的简单使用

    说实话自从大学毕业后已经很久没有用c语言写过程序了,一般都是使用c++,c++的stl和boost等,这些代码库大大简化了我们的编程复杂度.由于最近某种原因在次开始用c写程序.我是个比较懒的人,比较喜 ...

  9. openMP的一点使用经验

    最近在看多核编程.简单来说,由于现在电脑CPU一般都有两个核,4核与8核的CPU也逐渐走入了寻常百姓家,传统的单线程编程方式难以发挥多核CPU的强大功能,于是多核编程应运而生.按照我的理解,多核编程可 ...

  10. gnuplot常用技巧

      一.         基础篇: 在linux命令提示符下运行gnuplot命令启动,输入quit或q或exit退出. 1.plot命令 gnuplot> plot sin(x) with l ...