由于两种主要的浏览器(Netscape 和 Internet Explorer)不断地将新的 HTML 标签和属性(比如字体标签和颜色属性)添加到 HTML 规范中,创建文档内容清晰地独立于文档表现层的站点变得越来越困难。
样式表极大地提高了工作效率
样式表定义如何显示 HTML 元素,就像 HTML 3.2 的字体标签和颜色属性所起的作用那样。样式通常保存在外部的 .css 文件中。通过仅仅编辑一个简单的 CSS 文档,外部样式表使你有能力同时改变站点中所有页面的布局和外观。
由于允许同时控制多重页面的样式和布局,CSS 可以称得上 WEB 设计领域的一个突破。作为网站开发者,你能够为每个 HTML 元素定义样式,并将之应用于你希望的任意多的页面中。如需进行全局的更新,只需简单地改变样式,然后网站中的所有元素均会自动地更新。
Multiple styles will be stacked into one.
Style sheets allow style information to be specified in multiple ways. Styles can be specified within a single HTML element, within the head element of an HTML page, or in an external CSS file. It is even possible to reference multiple external style sheets within the same HTML document.
Cascading order
When the same HTML element is defined by more than one style, which style will be used?
Generally, all styles will be stacked into a new virtual style sheet according to the following rules, where the number 4 has the highest priority.
- Browser default settings
- External style sheet
- Internal style sheet (located within the <head> tag)
- Inline style (within HTML elements)
Therefore, inline styles (within HTML elements) have the highest priority, which means they will take precedence over the following style declarations: style declarations in the <head> tag, style declarations in external style sheets, or style declarations in the browser (default value).