专注优质Wordpress企业网站搭建与优化

《CSS权威指南 – 第3版》撷英笔记及配套视频:Grouping Selector–选择符群组



如果要将网页中H2标题和段落都设置为灰色,可以使用以下选择符群组方式:

  1. h2, p {color: gray;}

不同的HTML标签之间用英文逗号进行分隔,告诉浏览器这里有多个标签元素,当然如果不加这个逗号也是一种选择符群组的方式,但却是完全不同的含义,这点稍后会提到。

CSS规则比较多的时候,选择符的群组可以很灵活,类似于数学中的交集和并集(不知道这个比喻恰不恰当,数学是偶的死穴…),可以衍生出多种不同的CSS编写方式,当然我们要从中总结最简洁的一种。书中举例相同效果的三种不同群组方式,我看着有点头晕,就不解释了:

  1. /* group 1 */
  2. h1 {color: silver; background: white;}
  3. h2 {color: silver; background: gray;}
  4. h3 {color: white; background: gray;}
  5. h4 {color: silver; background: white;}
  6. b {color: gray; background: white;}
  1. /* group 2 */
  2. h1, h2, h4 {color: silver;}
  3. h2, h3 {background: gray;}
  4. h1, h4, b {background: white;}
  5. h3 {color: white;}
  6. b {color: gray;}
  1. /* group 3 */
  2. h1, h4 {color: silver; background: white;}
  3. h2 {color: silver;}
  4. h3 {color: white;}
  5. h2, h3 {background: gray;}
  6. b {color: gray; background: white;}

《CSS选择符群组》参考资料

CSS选择符总结

《CSS选择符群组》相关视频教程下载【FLV格式 – 5.36MB】

《CSS权威指南 – 第3版》撷英笔记及配套视频:Grouping Selector–选择符群组

[ 以下内容您也可能感兴趣 ]

Add a Comment