博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[CSS3] Understand CSS Selector Specificity
阅读量:5310 次
发布时间:2019-06-14

本文共 859 字,大约阅读时间需要 2 分钟。

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. 

转载于:https://www.cnblogs.com/Answer1215/p/10100201.html

你可能感兴趣的文章
centos中YUM安装后文件的常见路径
查看>>
链路聚合的优点
查看>>
gdb core调试
查看>>
Centos7下安装与卸载Jdk1.8
查看>>
POJ1328Radar Installation贪心+模拟队列+结构体排序+运算符重载+构造函数
查看>>
EOF:getchar()函数返回的一个特殊值
查看>>
ms-sql 转换成带千分位,并保留两位小数
查看>>
自动装箱、自动拆箱
查看>>
BZOJ3171: [Tjoi2013]循环格
查看>>
百度地图
查看>>
java的第3次作业
查看>>
移动平均
查看>>
Json文件
查看>>
实现一个基于FTP协议的程序——文件上传下载器(十三)
查看>>
Python2.7-itertools
查看>>
三种实现Android主界面Tab的方式
查看>>
MyEclipse2014安装包附注册破解包、eclipse安装包
查看>>
ubuntu apt-get failed
查看>>
AtCoder Grand Contest 018 E - Sightseeing Plan
查看>>
在Mac OSX EI Capitan下安装xgboost的吐血经历
查看>>