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. 离线功能对比:service worker和applicationCache

    SW 复杂,事件驱动,可以拦截请求,和缓存这些请求的响应数据,实现的效果更加灵活 AppCache 简单易用,声明式的将要缓存的文件清单声明在一个文件中.由于设计上的原因,它存在一些问题,导致难以运用 ...

  2. python--subprocess,粘包现象与解决办法,缓冲区

    一. subprocess 的简单用法 import subprocess sub_obj = subprocess.Popen( 'dir', #系统指令 shell=True, #固定方法 std ...

  3. Python从文件中读取数据

    一.读取整个文件内容 在读取文件之前,我们先创建一个文本文件resource.txt作为源文件. resource.txt my name is joker, I am 18 years old, H ...

  4. int long long 的范围

    unsigned   int     0-4294967295   (10位数,4e9) int                        -2147483648-2147483647  (10位 ...

  5. 1 producer — n consumers 模型 实现

    #include<stdio.h> #include<string.h> #include<pthread.h> #include<stdlib.h> ...

  6. idea导入jdk源码查看(xjl456852原创)

    idea添加了jdk环境后,却无法查看jdk源码,只能通过idea自带的反编译查看,看起来有些不爽. 下面来说一下如何设置,导入jdk源码,查看时通过源码查看jdk. 1.点击菜单 File -> ...

  7. Java-将字符串转为数字

    package com.tj; public class MyClass implements Cloneable { public static void main(String[] args) { ...

  8. Java单例模式简单实现

    代码 public class Singleton { private static Singleton singleton;//创建一个单例对象 public static Singleton ge ...

  9. appium之toast处理

    注意 toast要appium1.6.3以上版本才支持,Android 5.0以上(需使用夜神多开模拟器),jdk1.8且配置了环境变量. toast定位 1.先看下toast长什么样,如下图,像这种 ...

  10. 大数据学习——sqoop安装

    1上传  sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz 2解压 .bin__hadoop--alpha.tar.gz 3重命名 .bin__hadoop--al ...