13.1.1 CSS属性值的描述语法
本节描述属性值的合法取值范围。下面是其取值的几种方法:
- CSS关键词(例如
auto,red,disc等) - CSS基本数据类型,基本类型使用包含在尖括号中的类型名表示(例如<length>、<number>等)
- 取值与其属性取值范围一致的类型,使用包含在尖括号中的带有引号的属性名表示(例如<'border-top-color'>等)
- 取值不同于其属性的类型,使用包含在尖括号中的属性名表示(例如<margin-width>、<border-width>等)
值可以按照下面的方法组织,类似于正则表达式
- 几个并列的词:并列的词必须全部出现,次序和列出时一样
- 竖线
|分割两个或多个选择:其中只有一个出现 - 双竖线
||分割两个或多个选择:其中一个或多个出现,次序任意 - 两个与符号
&&分割两个或多个选择:必须全部出现的,次序任意 - 方框
[ ]用来分组
方框优先于并列,并列优先于两个与符号&&,两个与符号&&优先于双竖线||,双竖线||优先于竖线|。因此,下面两行的含义是一样的:
a b|c||d&&e f[a b] | [c|| [d&& [e f]]]
每个类型,关键词或方框组可以紧跟下列修改项中的一个:
- 星号
*表示前述的类型、词或分组出现0或多次 - 加号
+表示前述的类型、词或分组出现一次或多次 - 问号
?表示前述的类型、词或分组是可选的 - 以花括号
{A,B}分割的表示前述的类型、词或分组至少出现A次,最多出现B次
引用网址:http://www.dreamdu.com/css/property_value/
猴子提示: 梦之都教程中的CSS属性的取值全部使用本节介绍的方法描述,下面是一些示例
示例
<color>| inherit
代表<color>与inherit有且只能出现一个
真实的示例见color属性
[<background-color>||<background-image>||<background-repeat>||<background-attachment>||<background-position>] | inherit
代表[<background-color> || <background-image> || <background-repeat> || <background-attachment> || <background-position>]与inherit有且只能出现一个
真实的示例见background属性
[<background-color>||<background-image>||<background-repeat>||<background-attachment>||<background-position>]
代表<background-color>、<background-image>、<background-repeat>、<background-attachment>、<background-position>可以出现一个或多个
[ [<percentage>|<length>| left | center | right ] [<percentage>|<length>| top | center | bottom ]? ] | [ [ left | center | right ] || [ top | center | bottom ] ] | inherit
代表[ [ <percentage> | <length> | left | center | right ] [ <percentage> | <length> | top | center | bottom ]? ]与[ [ left | center | right ] || [ top | center | bottom ] ]与inherit有且只能出现一个
真实的示例见background-position属性
[ [<percentage>|<length>| left | center | right ] [<percentage>|<length>| top | center | bottom ]? ]
代表[ <percentage> | <length> | left | center | right ]必须出现,[ <percentage> | <length> | top | center | bottom ]为可选(?代表可选)
真实的示例见background-position属性
[[<family-name>|<generic-family>] [,<family-name>|<generic-family>]* ]
代表[ <family-name> | <generic-family> ]必须出现,[, <family-name>| <generic-family>]可以出现0次或多次(*代表出现0次或多次)
真实的示例见font-family属性
<border-width>{1,4}
代表<border-width>最少出现1次,最多出现4次
真实的示例见border-width属性