--- title: CSS3 slug: Archive/CSS3 tags: - CSS - CSS 参考 - CSS3 - 进阶 translation_of: Archive/CSS3 ---
CSS3 是层叠样式表(Cascading Style Sheets)语言的最新版本,旨在扩展CSS2.1。
它带来了许多期待已久的新特性, 例如圆角、阴影、gradients(渐变) 、transitions(过渡) 与 animations(动画) 。以及新的布局方式,如 multi-columns 、 flexible box 与 grid layouts。实验性特性以浏览器引擎为前缀(vendor-prefixed),应避免在生产环境中使用,或极其谨慎地使用,因为将来它们的语法和语义都有可能被更改。
CSS Level 2 经历了 9 年的时间(从 2002 年 8 月到 2011 年 6 月)才达到 Recommendation(推荐) 状态,主要原因是被一些次要特性拖了后腿。为了加快那些已经确认没有问题的特性的标准化速度,W3C 的 CSS Working Group(CSS 工作组) 作出了一项被称为 Beijing doctrine 的决定,将 CSS 划分为许多小组件,称之为模块。这些模块彼此独立,按照各自的进度来进行标准化。其中一些已经是 W3C Recommendation 状态,也有一些仍是 early Working Drafts(早期工作草案)。当新的需求被肯定后, 新的模块也会同样地添加进来。
从形式上来说,CSS3 标准自身已经不存在了。每个模块都被独立的标准化,现在标准 CSS 包括了修订后的 CSS2.1 以及完整模块对它的扩充,模块的 level(级别)数并不一致。可以在每个时间点上为 CSS 标准定义一个 snapshots(快照),列出 CSS 2.1 和成熟的模块。
W3C 会定期的发布这些 snapshots,如 2007, 2010, 2015 或 2017。
目前为止,还没有 level 超过 3 的模块被标准化,未来应该会有所改变。 不过有些模块,比如 Selectors(选择器)4 或 CSS Borders and Backgrounds(边框和背景)Level 4 早已拥有了 Editor's Draft(编辑草案),即使它们还没达到 First Published Working Draft(初次发布工作草案)状态。
有些 CSS 模块已经十分稳定,其状态为 CSSWG 规定的三个推荐品级之一:Candidate Recommendation(候选推荐), Proposed Recommendation(建议推荐)或 Recommendation(推荐)。表明这些模块已经十分稳定,使用时也不必添加前缀, 但有些特性仍有可能在 Candidate Recommendation 阶段被放弃。
这些模块扩展并修改了 CSS2.1 规范(核心规范)。 以下为 CSS 规范当前的 snapshot。
{{ SpecName("CSS3 Colors", "", "") }} | {{ Spec2("CSS3 Colors") }} 自 2011 年 6 月 7 日 |
增加 {{ cssxref("opacity") }} 属性,还有
它废弃了 system-color keywords(系统颜色关键字), 它们已经不能在生产环境中使用。 |
{{ SpecName("CSS3 Selectors", "", "") }} | {{ Spec2("CSS3 Selectors") }} 自 2011 年 9 月 29 日 |
增加:
|
下一个迭代的选择器规范早已开始运作,它还没有达到 First Public Working Draft 阶段。
{{ SpecName("CSS3 Namespaces", "", "") }} | {{ Spec2("CSS3 Namespaces") }} 自 2011 年 9 月 29 日 |
通过定义 CSS qualified name(CSS 限定名) 的概念来增加对 XML Namespace(名空间) 的支持, 使用 ' |
{{ SpecName("CSS3 Media Queries", "", "") }} | {{ Spec2("CSS3 Media Queries") }} 自 2012 年 6 月 19 日 |
将之前的媒体类型 ( 媒体查询并非仅能用于 CSS 文档中,它也被用于 HTML 元素的某些属性中, 例如 {{ HTMLElement("link") }} 元素的 {{ htmlattrxref("media","link") }} 属性。 |
该规范的下一个迭代也在进行中,借助新的媒体特征例如 hover
或 pointer,可以在 User Agent(用户代理) 上对 Web 站点的输入方法进行定制。
对 ECMAScript 的检测, 使用 script
媒体特征也已经被提出。
{{ SpecName("CSS3 Style", "", "") }} | {{ Spec2("CSS3 Style") }} 自 2013 年 11 月 7 日 |
正式定义了 HTML style 全局属性内容的语法。 |
{{ SpecName("CSS3 Backgrounds", "", "") }} | {{ Spec2("CSS3 Backgrounds") }} |
增加:
|
背景和边框规范的 CSS4 迭代早已进行,即便它还没有达到 First Public Working Draft 阶段,它计划增加对边框的裁剪功能 (借助 CSS {{ cssxref("border-clip") }},{{ cssxref("border-clip-top") }},{{ cssxref("border-clip-right") }},{{ cssxref("border-clip-bottom") }} 和 {{ cssxref("border-clip-left") }} 属性) 或边框一角的形状 (使用 CSS {{ cssxref("border-corner-shape") }} 属性)。
{{ SpecName("CSS3 Multicol", "", "") }} | {{ Spec2("CSS3 Multicol") }} |
增加简单的多列布局, 使用 CSS {{ cssxref("columns") }}, {{ cssxref("column-count") }}, {{ cssxref("column-fill") }}, {{ cssxref("column-gap") }}, {{ cssxref("column-rule") }}, {{ cssxref("column-rule-color") }}, {{ cssxref("column-rule-style") }}, {{ cssxref("column-rule-width") }}, {{ cssxref("column-span") }}, {{ cssxref("column-width") }}, {{ cssxref("break-after") }}, {{ cssxref("break-before") }}, 和{{ cssxref("break-inside") }}。 |
{{ SpecName("CSS3 Speech", "", "") }} | {{ Spec2("CSS3 Speech") }} |
定义 speech 媒体类型,一个 aural formatting model(听觉格式化模型) 和多个用于 speech-rendering(语音呈现) 用户代理的属性。 |
{{ SpecName("CSS3 Images", "", "") }} | {{ Spec2("CSS3 Images") }} |
定义 {{cssxref("<image>")}} 数据类型。 扩充 增加:
|
用于取代 CSS Image Level 3 的 CSS Image Values and Replaced Content Level 4 正在发展中,目前为 {{Spec2("CSS4 Images")}}。
{{ SpecName("CSS3 Values", "", "") }} | {{ Spec2("CSS3 Values") }} |
使 正式定义了 CSS 2.1 中的 CSS 数据类型,之前是隐晦的由它们的语法记号和文本来定义。 增加:
有风险: 由于缺少足够的浏览器支持, |
像 <ident>
和 <custom-ident>
这样的类型定义在 CSS Values and Units Module Level 4 中被推迟。
{{ SpecName("CSS3 Flexbox", "", "") }} | {{ Spec2("CSS3 Flexbox") }} |
为 CSS {{ cssxref("display") }} 属性增加了 flexbox layout(伸缩盒布局) 及多个新 CSS 属性来控制它:{{ cssxref("flex") }},{{ cssxref("flex-align") }},{{ cssxref("flex-direction") }},{{ cssxref("flex-flow") }},{{ cssxref("flex-item-align") }},{{ cssxref("flex-line-pack") }},{{ cssxref("flex-order") }},{{ cssxref("flex-pack") }} 和 {{ cssxref("flex-wrap") }}。 |
{{ SpecName("CSS3 Conditional", "", "") }} | {{ Spec2("CSS3 Conditional") }} |
增加了对样式表部分内容进行条件处理的功能, 若浏览器或文档的能力符合条件,则该部分的样式生效。它主要是允许了在 {{ cssxref("@media") }} 中嵌套 @ 规则, 增加了一个新的 CSS @ 规则, {{ cssxref("@supports") }} 和一个新的 DOM 方法 {{domxref("CSS.supports()")}}。 |
{{ SpecName("CSS3 Text Decoration", "", "") }} | {{ Spec2("CSS3 Text Decoration") }} |
扩展:
增加:
明确:
有风险: 由于缺少足够的浏览器支持, |
{{ SpecName("CSS3 Fonts", "", "") }} | {{ Spec2("CSS3 Fonts") }} |
修正 CSS2.1 字体匹配算法,以便接近于真实的实现。 增加:
|
{{ SpecName("CSS3 Cascade", "", "") }} | {{ Spec2("CSS3 Cascade") }} |
增加:
明确:
|
{{ SpecName("CSS3 Writing Modes", "", "") }} | {{ Spec2("CSS3 Writing Modes") }} |
定义了水平和垂直脚本书写模式,概况了 CSS {{ cssxref("direction") }} 和 {{ cssxref("unicode-bidi") }} 属性是如何与新 CSS {{ cssxref("text-orientation") }} 属性相互之间产生影响的,并在需要它们的地方扩展它们。 |
{{ SpecName("CSS Shapes", "", "") }} | {{ Spec2("CSS Shapes") }} |
定义了可用于浮动(float)的几何图形。这些图形描述了行内元素可被包裹的区域,而非包裹其边界框( bounding box)。 |
{{ SpecName("CSS Masks", "", "") }} | {{ Spec2("CSS Masks") }} |
定义了部分或完整隐藏可视元素的一种方式。其描述了如何使用另一图形元素或图片作为亮度遮罩(luminance)或透明度遮罩(alpha)。 |
处于改善阶段(refining phase)的规范已基本稳定。虽然还有可能被修改,但不会和当前的实现产生冲突;其主要定义在个别特殊情况的行为。
{{ SpecName("Web Animations", "", "") }} | {{ Spec2("Web Animations") }} |
{{ SpecName("CSS3 Counter Styles", "", "") }} | {{ Spec2("CSS3 Counter Styles") }} |
{{ SpecName("Compositing", "", "") }} | {{ Spec2("Compositing") }} |
{{ SpecName("CSS3 Syntax", "", "") }} | {{ Spec2("CSS3 Syntax") }} |
澄清如何确定字符集; 分析和标记化算法的最小变化。 |
{{ SpecName("CSS Will Change", "", "") }} | {{ Spec2("CSS Will Change") }} |
{{ SpecName("CSS3 Transitions", "", "") }} | {{ Spec2("CSS3 Transitions") }} |
通过增加 CSS {{ cssxref("transition") }},{{ cssxref("transition-delay") }},{{ cssxref("transition-duration") }}, {{ cssxref("transition-property") }},和 {{ cssxref("transition-timing-function") }} 属性来支持定义两个属性值间的 transitions effects(过渡效果)。 |
{{ SpecName("CSS3 Animations", "", "") }} | {{ Spec2("CSS3 Animations") }} |
允许定义动画效果, 借助于新增的 CSS {{ cssxref("animation") }}, {{ cssxref("animation-delay") }}, {{ cssxref("animation-direction") }}, {{ cssxref("animation-duration") }}, {{ cssxref("animation-fill-mode") }}, {{ cssxref("animation-iteration-count") }}, {{ cssxref("animation-name") }}, {{ cssxref("animation-play-state") }}, 和 {{ cssxref("animation-timing-function") }} 属性, 以及 {{ cssxref("@keyframes") }} @ 规则。 |
{{ SpecName("CSS3 Transforms", "", "") }} | {{ Spec2("CSS3 Transforms") }} |
增加:
注意: 该规范是 CSS 2D-Transforms, CSS 3D-Transforms 和 SVG transforms 合并的结果。 |
{{ SpecName("CSS3 Fragmentation", "", "") }} | {{ Spec2("CSS3 Fragmentation") }} |
定义了网页的分割将如何实行,即分页、分栏,以及窗口和孤儿页面的处理。 增加:
|
{{ SpecName("CSS3 Text", "", "") }} | {{ Spec2("CSS3 Text") }} |
扩展:
增加:
|
一部分出现在早期 CSS Text Level 3 草案中的特性被推迟到了该规范的下个迭代中。
{{ SpecName("CSS3 Variables", "", "") }} | {{ Spec2("CSS3 Variables") }} |
定义了允许在 CSS 中定义变量的机制。 |
{{ SpecName("Compositing", "", "") }} | {{ Spec2("Compositing") }} |
处于修正阶段的模块没处于改善阶段的模块稳定。它们的语法一般还需要详细审查,可能还会有些大变化,还有可能不兼容之前的规范。替代语法已通过测试并被广泛实践。
{{ SpecName("CSS3 Basic UI", "", "") }} | {{ Spec2("CSS3 Basic UI") }} | |
增加:
|
这里提供了会出现在下次 CSS Basic User Interface Module 迭代中的功能列表。
{{ SpecName("CSS3 Grid", "", "") }} | {{ Spec2("CSS3 Grid") }} |
添加了 grid 布局给 CSS display 属性,以及一些新的属性来控制它:{{cssxref("grid")}},{{cssxref("grid-area")}},{{cssxref("grid-auto-columns")}},{{cssxref("grid-auto-flow")}},{{cssxref("grid-auto-position")}}, {{cssxref("grid-auto-rows")}}, {{cssxref("grid-column")}}, {{cssxref("grid-column-start")}}, {{cssxref("grid-column-end")}}, {{cssxref("grid-row")}}, {{cssxref("grid-row-start")}}, {{cssxref("grid-row-end")}}, {{cssxref("grid-template")}}, {{cssxref("grid-template-areas")}}, {{cssxref("grid-template-rows")}}, and {{cssxref("grid-template-columns")}}. |
{{ SpecName("CSS3 Box Alignment", "", "") }} | {{ Spec2("CSS3 Box Alignment") }} |
{{ SpecName("CSS3 Paged Media", "", "") }} | {{ Spec2("CSS3 Paged Media") }} |
{{ SpecName("CSSOM View", "", "") }} | {{ Spec2("CSSOM View") }} |
{{ SpecName("CSS4 Selectors", "", "") }} | {{ Spec2("CSS4 Selectors") }} |
{{ SpecName("CSS4 Images", "", "") }} | {{ Spec2("CSS4 Images") }} |
扩展:
增加:
|
{{ SpecName("CSS3 Device", "", "") }} | {{ Spec2("CSS3 Device") }} |
增加一个新的 @ 规则, {{ cssxref("@viewport") }},允许为视口指定尺寸(size)、缩放因子(zoom factor)和方向(orientation),这些将作为 initial containing block(初始包含块) 的基础。 |
{{ SpecName("CSS3 GCPM", "", "") }} | {{ Spec2("CSS3 GCPM") }} |
增加调整打印版本的功能,允许控制页头,页脚,同时引用表索引或表内容。 |
{{ SpecName("CSS3 Exclusions", "", "") }} | {{ Spec2("CSS3 Exclusions") }} |
扩展浮动机制,在任何定位方案中生成一个 exclusion regions(排斥区域)。增加形状标记,其中的内容必须流动。 |
{{ SpecName("CSS3 Lists", "", "") }} | {{ Spec2("CSS3 Lists") }} |
扩展了列表计数机制, 这样可以为列表标记设置样式,并使 Web 开发者定义新的列表计数方案。 |
{{ SpecName("CSS3 Regions", "", "") }} | {{ Spec2("CSS3 Regions") }} |
定义了一种可使内容流动至数个非连续空间的机制,称为区域(Regions)。 |
{{ SpecName("Filters 1.0", "", "") }} | {{ Spec2("Filters 1.0") }} |
{{ SpecName("CSS3 Template", "", "") }} | {{ Spec2("CSS3 Template") }} |
{{ SpecName("CSS3 Sizing", "", "") }} | {{ Spec2("CSS3 Sizing") }} |
{{ SpecName("CSS Line Grid", "", "") }} | {{ Spec2("CSS Line Grid") }} |
{{ SpecName("CSS3 Positioning", "", "") }} | {{ Spec2("CSS3 Positioning") }} |
{{ SpecName("CSS3 Ruby", "", "") }} | {{ Spec2("CSS3 Ruby") }} |
{{ SpecName("CSSOM", "", "") }} | {{ Spec2("CSSOM") }} |
{{ SpecName("CSS3 Overflow", "", "") }} | {{ Spec2("CSS3 Overflow") }} |
{{ SpecName("CSS3 Font Loading", "", "") }} | {{ Spec2("CSS3 Font Loading") }} |
{{ SpecName("CSS3 Display", "", "") }} | {{ Spec2("CSS3 Display") }} |
{{ SpecName("CSS Scope", "", "") }} | {{ Spec2("CSS Scope") }} |
{{ SpecName("CSS4 Media Queries", "", "") }} | {{ Spec2("CSS4 Media Queries") }} |
{{ SpecName("CSS Non-element Selectors", "", "") }} | {{ Spec2("CSS Non-element Selectors") }} |
{{ SpecName("Geometry Interfaces", "", "") }} | {{ Spec2("Geometry Interfaces") }} |
{ SpecName("CSS3 Inline", "", "") }} | {{ Spec2("CSS3 Inline") }} |
以下模块已经过时,需要重写。其语法仍然在审查,可能会以不兼容的方式发展出很多。替代语法已通过测试并被广泛实践。
{{ SpecName("CSS3 Box", "", "") }} | {{ Spec2("CSS3 Box") }} |
{{ SpecName("CSS3 Content", "", "") }} | {{ Spec2("CSS3 Content") }} |
{{ SpecName("CSS3 Inline Layout", "", "") }} | {{ Spec2("CSS3 Inline Layout") }} |