It is hard to explain css selector specificty, to easy way to understand it is by playing around with it.

To remember some rules can be helpful:

  • inline style > ID selector > Classes, attributes, and pseudo-classes > Elements and pseudop elements

Which means if you have inline style in your html, even you try to use ID selector, it cannot override the inline style. That's why people recommend don't use inline style because it is hard to override.

  • If one combine selector A has more specificty than the other B, A will override B, even B comes later.

First one is the winner.

  • If A and B has the same specificity, B comes later win.
  • !Important overrides all the rest. This is the most powerful one, but again it is hard to override in the future if needed, recommended not to use it as much as possible.

[CSS3] Understand CSS Selector Specificity的更多相关文章

  1. Selenium - CSS Selector

    Selenium - CSS Selector http://www.cnblogs.com/bugua/archive/2012/08/16/2641647.html   昨天我练习了用CSS(即层 ...

  2. css selector

    文章一: http://www.jb51.net/css/68287.html 去年我学jQuery的时候,曾经做过一点选择器(selector)的笔记,今天是CSS的选择器,以后还有一部分xPath ...

  3. Selenium 使用css selector (资源来源于网络)

    Selenium - CSS Selector 昨天我练习了用CSS(即层叠样式表Cascading Stylesheet) Selector来定位(locate)页面上的元素(Elements).S ...

  4. CSS selector All In One

    CSS selector All In One CSS selector https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors ...

  5. [译文]通过ID, TagName, ClassName, Name, CSS selector 得到element

    致谢原文: <http://xahlee.info/js/js_get_elements.html> 通过ID得到element: Document.getElementById(id s ...

  6. 转:Selenium之CSS Selector定位详解

    CSS selector定位 CSS(Cascading Style Sheets)是一种语言,它被用来描述 HTML 和 XML 文档的样式.  百度输入框: <input name=&quo ...

  7. Scrapy学习系列(一):网页元素查询CSS Selector和XPath Selector

    这篇文章主要介绍创建一个简单的spider,顺便介绍一下对网页元素的选取方式(css selector, xpath selector). 第一步:创建spider工程 打开命令行运行以下命令: sc ...

  8. Jsoup代码解读之五-实现一个CSS Selector

    Jsoup代码解读之七-实现一个CSS Selector 当当当!终于来到了Jsoup的特色:CSS Selector部分.selector也是我写的爬虫框架webmagic开发的一个重点.附上一张s ...

  9. css selector: xpath:

    css selector: $$(".mainLeft>div>h1") xpath: $x(".mainLeft>div>h1") n ...

随机推荐

  1. find 命令search使用

    GNU在目录树中查找的时候,是根据所给的名字从根节点开始从左到右匹配.根据优先级规则,直到在某一个节点找到结果了才会移动到下一个文件名字. 1.找空目录 find  ./path -depth -ty ...

  2. php框架的特性总结

    今天面试问到了php框架的特性,特此在这汇总一下,方便以后查看. Thinkphp 3.2特性: 1.多表查询非常方便,在model 里几句代码就可以完成完成多表的关联操作. 2.融合了smarty ...

  3. Java面试——HashCode的作用原理和实例解析

    ,也就是说,我们先通过 HashCode来判断两个类是否存放某个桶里,但这个桶里可能有很多类,那么我们就需要再通过 equals 在这个桶里找到我们要的类. 请看下面这个例子 : public cla ...

  4. android 之 Intent、broadcast

    Intent的功能有: 在mainActivity中为按钮1添加监听事件: listener1 = new OnClickListener() { @Override    public void o ...

  5. 九度oj 题目1139:最大子矩阵

    题目描述: 已知矩阵的大小定义为矩阵中所有元素的和.给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵. 比如,如下4 * 4的矩阵 0 -2 -7 0 9 2 -6 2 -4 1 ...

  6. ICMP TYPE CODE

    TYPE CODE Description Query Error 0 0 Echo Reply——回显应答(Ping应答) x   3 0 Network Unreachable——网络不可达   ...

  7. shell文件包含

    像其他语言一样,Shell 也可以包含外部脚本,将外部脚本的内容合并到当前脚本. Shell 中包含脚本可以使用: . filename 或 source filename 两种方式的效果相同,简单起 ...

  8. iOS长按控件

    前言 网上看到一个button的长按控件效果不错,一个菱形从中间向两边增大,研究了下 原理 上图红色是控件上面放了视图,从上到下分别是view,normalLable,highlightLabel,b ...

  9. iOS阴影

    但是如果把masksToBounds设置为yes就没有阴影了     UIButton *view = [[UIButton alloc]initWithFrame:CGRectMake(, , ,  ...

  10. BZOJ 4161 Shlw loves matrixI ——特征多项式

    矩阵乘法递推的新姿势. 叉姐论文里有讲到 利用特征多项式进行递推,然后可以做到k^2logn #include <cstdio> #include <cstring> #inc ...