CSS优先级、引入方式、Hack
优先级
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);
转载于:https://www.cnblogs.com/jununx/p/3332741.html
CSS优先级、引入方式、Hack相关推荐
- Day46(列表标签,表格标签,表单标签,css的引入方式,css选择器)
一.列表标签 列表标签分为三种. 1.无序列表<ul>,无序列表中的每一项是<li> 英文单词解释如下: ul:unordered list,"无序列表"的 ...
- python 全栈开发,Day46(列表标签,表格标签,表单标签,css的引入方式,css选择器)
一.列表标签 列表标签分为三种. 1.无序列表<ul>,无序列表中的每一项是<li> 英文单词解释如下: ul:unordered list,"无序列表"的 ...
- css的引入方式和选择器
目录 1.css介绍 2.css的引入方式 3.css的元素选择器 1.基本选择器 2.组合选择器 3.属性选择器 4.伪类选择器 5.伪元素选择器 1.css介绍 层叠样式表(英文全称:Cascad ...
- css层叠引入方式有,前端1-----CSS层叠样式表了解,css的引入方式,三大选择器(标签,类,id),高级选择器...
前端1-----CSS层叠样式表了解,css的引入方式,三大选择器(标签,类,id),高级选择器 一丶CSS简介 叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTM ...
- 前端1-----CSS层叠样式表了解,css的引入方式,三大选择器(标签,类,id),高级选择器...
前端1-----CSS层叠样式表了解,css的引入方式,三大选择器(标签,类,id),高级选择器 一丶CSS简介 叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTM ...
- 好程序员HTML5前端教程-css的引入方式和选择器
好程序员HTML5前端教程-css的引入方式和选择器 01.引入css方式(重点掌握) 行内样式 内接样式 外接样式 3.1 链接式 3.1 导入式 css介绍 现在的互联网前端分三层: HTML:超 ...
- CSS之引入方式和选择器
html 在一个网页中负责的事情是一个页面的结构 css(层叠样式表) 在一个网页中主要负责了页面的数据样式. 编写css代码的方式: 第一种: 在style标签中编写css代码. 只能用于本页面中, ...
- CSS 从入门到放弃系列:CSS的引入方式
css的四种引入方式 内联方式(行间样式) <div style="width:100px;height: 100px; background-color: red"> ...
- css样式引入方式,及常用设置标签样式
一. 三种样式引入方式 1. 内联式-直接写在div标签中,不推荐用 <div style="color:red;font-size:20px;font-family:'Microso ...
- CSS样式引入方式和部分CSS样式的设置
一.三种引入方式以及其应用场景 1.行间样式,当样式非常少.在一组选择器内需要优先样式,缺点是不是人看的代码样式,影响布局结构的视觉效果 a.写在起始标签的style属性里,各样式之间用": ...
最新文章
- 机器学习与数据科学 基于R的统计学习方法(基础部分)
- 重走丝绸之路:海尔如何探索全球生活智慧?
- 操作系统中的进程与线程
- 存储在icloud云盘文件夹顶层_苹果iCloud使用技巧:去弹窗~
- 新的Google Lyra音频编解码器对实时视频流意味着什么?
- 复制K2流程图实现记录
- 开课吧Java面试题:使用 this 和 super 要注意
- 华为云计算HCNA--存储虚拟化
- MyEclipse2014安装aptana插件
- springMVC学习(10)-上传图片
- python气象包_Python-Cartopy包: 地图投影
- html5 绘制思维导图,Qunee组件制作思维导图
- 科技部:中国131家独角兽企业 名单文字版
- 有线路由器后接无线路由器
- 快速搭建基于《搜狗微信》的公众号爬虫---搜狗微信公众号爬虫教程
- 再谈自适应学习——技术篇
- 单边指数信号的特点_方波和单边指数信号的卷积.doc
- nxn次方求和函数_算法|小学生都能看懂的生成函数入门教程
- linux red hat 8.0 root密码破解
- 从进化论的角度聊一聊大分子编码说和老王谬论
热门文章
- 两个网口芯片接一个变压器_电路中网络变压器件选型和PCB
- mysql 子查询空_mysql的子查询
- SRv6技术研究和组网设计
- Android P版本怎么简单的验证HIDL的Demo例程
- uCOS-II中的任务切换机制
- Package has no installation candidate
- winpcap基本原理及常见应用_锁相放大器的基本原理(Part 1)
- hive order by sort by distribute by总结
- html5旋转木马效果,js实现旋转木马效果
- frpc在linux下开机启动,frp 设置开机自启