用层叠管理多样式(Managing Multiple Styles: The Cascade)
来源:互联网 发布:linux file 头文件 编辑:程序博客网 时间:2024/06/05 07:10
内容参考自《CSS实践手册》第二版
层叠是决定哪些样式属性要被应用到元素的一套规则。
继承样式的叠加
<html><head><title>Hello world!</title><style type="text/css">body {font-family:Arial, Helvetica, sans-serif;}p {color:#00F;}strong {font-size:15px;}</style></head><body><p> <strong>Hello world!</strong></p></body></html>
<strong>标签嵌套在段落里面,这个段落又处在<body>里面,于是<strong>标签就会从它的两个祖先处得到继承,因此它从body处继承了font-family(字体)属性,又从父级段落处继承了color(颜色)属性,此外<strong>标签直接应用了font-size属性,所以<strong>标签的样式为
strong {font-family:Arial, Helvetica, sans-serif;color:#00F;font-size:15px;}
最近的祖先样式先胜出
如果body标签和段落标签都设置了color属性,则<strong>标签会继承段落处的color属性
直接应用的样式胜出
如果body标签和段落标签和<strong>标签都设置了color属性,<strong>样式比body标签和段落标签更具体
用权重值决定哪种样式——最具体的样式中的属性会胜出
一个标签选择器值1分
一个类选择器值10分
一个ID选择器值100分
一个内建样式值1000分
(这个计算在大多数情况下适用)
伪元素(如 :first-line)通常被当作标签选择器
伪类(如: :link)通常被当作类对待
一个标签多个样式则对其值求和
个人觉得用位数来说明更清楚,权重值用ABC来表示(a代表ID,b代表类,c代表标签),在相应的位数上加1
如
p(标签),权重值为001
.footer(类),权重值为010
#main(ID),权重值为100
div .footer,div为标签,在C位上加1,.footer为类,在B位上加1 权重值为011
div#main,权重值为101
div#main div.footer,权重值为211
权重值相同时最后一个样式胜出
主要看样式表在HTML中的位置了
忽略权重值
在属性后使用!important(注意IE6无效)
- 用层叠管理多样式(Managing Multiple Styles: The Cascade)
- The cascade SVM (串联SVM;层级SVM;层叠SVM)
- Activity生命周期管理(Managing the Activity Lifecycle)
- Managing Multiple Eclipse Installations
- microstation level2 1202 managing line styles
- Displaying Text In Multiple Styles
- Managing the Activity Lifecycle 管理活动的生命周期
- Managing the Activity Lifecycle--管理Activity生命周期
- (三)Managing the Activity Lifecycle管理activity的生命周期
- Managing Multiple Screens in JavaFX
- CSS学习(2)层叠cascade
- CSS中的样式层叠机制Cascade
- Managing the Undo Tablespace
- Managing the Keyboard
- Managing the Keyboard
- Managing the Activity Lifecycle
- Managing the Activity Lifecycle
- Managing the System UI
- ETL介绍(转)
- WP7-Windows Phone 7 培训总结
- Linux的分段和分页机制
- doc文档保护
- android兼容性测试CTS
- 用层叠管理多样式(Managing Multiple Styles: The Cascade)
- 降低即时搜索的服务器压力
- Linux内存布局
- vs 11 express 显示datapicker
- java对javascript语法分析
- [UVA 103] Stacking Boxes
- NET的优势与劣势
- Linux页框管理
- WP7-检查手机网络