部分来自456bereastreet

an overview of the syntax for all CSS 2.1 selectors (based on the table in CSS 2.1, 5.1 Pattern matching):

Overview of CSS 2.1 selector syntax
Selector type Pattern Description
Universal * Matches any element.
Type E Matches any E element.
Class .info Matches any element whose class attribute contains the value info.
ID #footer Matches any element with an id equal to footer.
Descendant E F Matches any F element that is a descendant of an E element.
Child E > F Matches any F element that is a child of an E element.
Adjacent E + F Matches any F element immediately preceded by a sibling element E.
Attribute E[att] Matches any E element that has an att attribute, regardless of its value.
Attribute E[att=val] Matches any E element whose att attribute value is exactly equal to val.
Attribute E[att~=val] Matches any E element whose att attribute value is a list of space-separated values, one of which is exactly equal to val.
Attribute E[att|=val] Matches any E element whose att attribute has a hyphen-separated list of values beginning with val.
The :first-child pseudo-class E:first-child Matches element E when E is the first child of its parent.
The link pseudo-classes E:link
E:visited
Matches not yet visited (:link) or already visited (:visited) links.
The dynamic pseudo-classes E:active
E:hover
E:focus
Matches E during certain user actions.
The :language pseudo-class E:lang(c) Matches elements of type E that are in language c.
The :first-line pseudo-element E:first-line Matches the contents of the first formatted line of element E.
The :first-letter pseudo-element E:first-letter Matches the first letter of element E.
The :before and :after pseudo-elements E:before
E:after
Used to insert generated content before or after an element’s content.

I’ll explain each of these selector types in more detail in this two part article, so keep reading. A few terms used in that table and in the rest of this article may need some clarification:

descendant
An element that is the child, grandchild or later descendant of an element in the document tree.
ancestor
An element that is the parent, grandparent or earlier ancestor of an element in the document tree.
child
The direct descendant of an element. No other elements may come between the two in the document tree.
parent
The direct ancestor of an element. No other element may come between the two in the document tree.
sibling

An element that has the same parent as the current element.

元素也可以基于它们的类而被选择:

td.fancy {color: #f60;background: #666;}

在上面的例子中,类名为 fancy 的表格单元将是带有灰色背景的橙色。

You can assign multiple class names to an element – the class attribute can hold a space separated list of class names. Class selectors can then be used to target only elements which have several class names. This rule will match p elements which haveboth “info” and “error” in their list of class names:

  1. p.info.error { color:#900; font-weight:bold; }

Multiple attribute selectors can be used in the same selector. This makes it possible to match against several different attributes for the same element. The following rule would apply to all blockquote elements that have a class attribute whose value is exactly “quote”, and a cite attribute (regardless of its value):

  1. blockquote[class=quote][cite] { color:#f00; }

An element may match several pseudo-classes at the same time. An element could have focus and be hovered over, for instance:

  1. input[type=button]:focus {
  2. color:#000;
  3. background:#ffe;
  4. }
  5. input[type=text]:focus:hover {
  6. background:#fff;
  7. }

The first rule will match single line input elements that have focus, and the second rule will match the same elements when they are also hovered over.

属性选择器在为不带有 class 或 id 的表单设置样式时特别有用:

Each of the selectors that form a descendant selector can be a simple selector of any form. The selector in the following rule matches all p elements with a class name of infothat are contained by an li element that is contained by a div element with the id myid.

  1. div#myid li p.info { color:#f00; }

The mistake many make is to not list the full selectors. Assume that you have the following markup:

  1. <div id="news">
  2. <h3>News</h3>
  3. <ul>
  4. <li>Item 1</li>
  5. <li>Item 2</li>
  6. </ul>
  7. </div>

Now, say you want to apply the same amount of margin to level 3 headings and unordered lists, but only if they are in the div element whose id is “news”. Here is thewrong way:

  1. div#news h3, ul {
  2. margin:0 2em;
  3. }

This will affect both h3 and ul elements in div#news. The problem is that it will targetall ul elements in the document, not only those in div#news.

Here is the correct way of grouping the selectors in this case:

  1. div#news h3,
  2. div#news ul {
  3. margin:0 2em;
  4. }

So, when grouping selectors, remember to fully specify each selector.

关于!important

#box {
     color:red !important;
     color:blue;
 }

HTML

<div id="Box"> 在不同的浏览器下,这行字的色应该不同!</div>

这个例子应该是大家经常见到的important的用法了,在IE6环境下,这行字是蓝色,在IE7及firefox下,为红色。这是因为IE6不认important(即不认 !importmant 但是还是认!important前面的color:red),并且color:blue放在color:red的后面(后面的css定义覆盖了前面的color:red),所以在IE6下字为蓝色;而在IE7及firefox下important级别优先,所以color:red !important;和color:blue;的前后顺序没有关系,在IE7及firefox下red跟blue谁先谁后都没有关系。

我们所认为的“字体”可能有许多字体变形组成,分别用来描述粗体、斜体文本,等等。例如,你可能已经对字体 Times 很熟悉。不过,Times 实际上是多种变形的一个组合,包括 TimesRegular、TimesBold、TimesItalic、TimesOblique、TimesBoldItalic、TimesBoldOblique,等等。Times 的每种变形都是一个具体的字体风格(font face),而我们通常认为的 Times 是所有这些变形字体的一个组合。换句话说,Times 实际上是一个字体系列(font family),而不只是单个的字体,尽管我们大多数人都认为字体就是某一种字体。

除了各种特定字体系列外(如 Times、Verdana、Helvetica 或 Arial),CSS 还定义了 5 种通用字体系列:

Serif 字体
这些字体成比例,而且有上下短线。如果字体中的所有字符根据其不同大小有不同的宽度,则该字符是成比例的。例如,小写 i 和小写 m 的宽度就不同。上下短线是每个字符笔划末端的装饰,比如大写 l 顶部和底部的短线,或大写 A 两条腿底部的短线。Serif 字体的例子包括 Times、Georgia 和 New Century Schoolbook。
Sans-serif 字体
这些字体是成比例的,而且没有上下短线。Sans-serif 字体的例子包括 Helvetica、Geneva、Verdana、Arial 或 Univers。
Monospace 字体
Monospace 字体并不是成比例的。它们通常用于模拟打字机打出的文本、老式点阵打印机的输出,甚至更老式的视频显示终端。采用这些字体,每个字符的宽度都必须完全相同,所以小写的 i 和小写的 m 有相同的宽度。这些字体可能有上下短线,也可能没有。如果一个字体的字符宽度完全相同,则归类为 Monospace 字体,而不论是否有上下短线。Monospace 字体的例子包括 Courier、Courier New 和 Andale Mono。
Cursive 字体
这些字体试图模仿人的手写体。通常,它们主要由曲线和 Serif 字体中没有的笔划装饰组成。例如,大写 A 再其左腿底部可能有一个小弯,或者完全由花体部分和小的弯曲部分组成。Cursive 字体的例子包括 Zapf Chancery、Author 和 Comic Sans。
Fantasy 字体

这些字体无法用任何特征来定义,只有一点是确定的,那就是我们无法很容易地将其规划到任何一种其他的字体系列当中。这样的字体包括 Western、Woodblock 和 Klingon。

看了这些,终于知道Chrome的字体设置里面那么多选项是什么意思了,哈哈!

转载于:https://www.cnblogs.com/JPAORM/archive/2011/12/15/2509779.html

CSS学习笔记----选择器与字体(字系)相关推荐

  1. CSS学习笔记----CSS3自定义字体图标

    响应式网页字体图标 作者:大漠 日期:2014-01-28 点击:3220 @font-face Responsive 本文由大漠根据Jason的<Responsive Webfont Icon ...

  2. html css学习笔记-href 表格 字体 轮郭

    <!DOCTYPE html> <html> <head lang="en"><meta charset="UTF-8" ...

  3. HTML/CSS学习笔记03【CSS概述、CSS选择器、CSS属性、CSS案例-注册页面】

    w3cschool菜鸟教程.CHM(腾讯微云):https://share.weiyun.com/c1FaX6ZD HTML/CSS学习笔记01[概念介绍.基本标签.表单标签][day01] HTML ...

  4. CSS学习笔记(详细,不定期更新)

    CSS 学习笔记 CSS书写规范 顺序 布局位置属性(position, top, right, z-index, display, float等) 自身大小盒子模型(width, height, p ...

  5. CSS学习笔记 #20201119

    CSS学习笔记 #20201119 目录 文章目录 CSS学习笔记 #20201119 目录 引言 选择器 权值 样式 引言 CSS能搭配HTML文档,将网页繁杂的 样式信息 从HTML文档中 相对独 ...

  6. CSS学习笔记(狂神-完整版)

    CSS学习笔记(狂神-完整版) HTML + CSS + JavaScript 结构 + 表现 + 动作 1.什么是CSS 如何学习 CSS是什么 CSS怎么用(快速入门) CSS选择器(重点+难点) ...

  7. HTML/CSS学习笔记01【概念介绍、基本标签】

    w3cschool菜鸟教程.CHM(腾讯微云):https://share.weiyun.com/c1FaX6ZD HTML/CSS学习笔记01[概念介绍.基本标签.表单标签][day01] HTML ...

  8. css中怎么加入立体模型,CSS学习笔记二:css 画立体图形

    继上一次学了如何去运用css画平面图形,这一次学如何去画正方体,从2D向着3D学习,虽然有点满,但总是一个过程,一点一点积累,然后记录起来. Transfrom3D 在这一次中运用到了一下几种属性: ...

  9. CSS学习笔记(详细)- 基础

    CSS学习笔记从零开始 代码风格 样式书写格式 CSS基础选择器 css选择器的作用:(选择标签用的) 选择器分类:基础选择器和复合选择器 基础选择器 标签选择器 类选择器 - 开发最常用 多类名 i ...

最新文章

  1. 路由协议OSPF知识点汇总
  2. 重温强化学习之基于模型方法:动态规划
  3. qpid java_AMQP与QPID简介
  4. 一发模拟水题但是RE,暑假抽个时间改一改、、
  5. 判断IE中某个ActiveX控件是否已经安装
  6. 链表删除功能实现演示
  7. SQL必知必会-存储过程
  8. 码匠编程:CSS让元素绝对居中,你知道几种方法?
  9. OUTLOOK新邮件到达提醒设置以及outlook最小化到托盘设置
  10. Redis基本命令及相关用法
  11. ad17如何删除3d实体_多年工作积累的Altium AD09 AD17 硬件元器件 原理图库+PCB封装库...
  12. 最新个人自动发卡系统7.0网站源码开源
  13. Android Camera processCaptureResult 分析
  14. ecplise 设置代码自动提示功能
  15. 苹果电脑键盘没反应_MAC PRO type-c接口无反应,充电无反应或一直在充电解决方案...
  16. 1002. 写出这个数 (20)练习
  17. git - - - .gitignore
  18. 疫情之下裸辞后的一些感悟和面试心得
  19. 风暴——老奶雷加尔使用心得
  20. spring cloud netfilx

热门文章

  1. NetBeans+xdebug解决无法连接xdebug问题
  2. 发现VB6中SAX的乐趣[转]
  3. 【Java从0到架构师】git 核心原理和分支管理
  4. 7zip和winrar命令行备份
  5. 三个方法教你做词云图,连文科生都能轻松学会
  6. CSS 常用中文字体的英文名称
  7. mysql 5.5 client 字符集_MySQL 5.5.28字符集的设置_MySQL
  8. ft2232驱动安装方法_教你win10系统显卡驱动安装失败的解决方法「系统天地」
  9. 下载电子书,给电子书添加总目录页面
  10. 使用fetch函数发送ajax