Introduction to HTML Part 2 HTML简介第2部分

Introduction to Styles 样式简介:

A style is a set of HTML code that identifies what style attributes will be applied to different HTML elements. Although there are many different style attributes that can be applied to different HTML elements, but some of the most commonly used style attributes are:“border”, “padding”, “background”, “color”, and “font”. These style attributes can be used by themselves or in combination with other style attributes.

样式是一组HTML代码,用于标识将应用于不同HTML元素的样式属性。虽然有许多不同的样式属性可以应用于不同的HTML元素,但一些最常用的样式属性是:“边框”、“填充”、“背景”、“颜色”和“字体”。这些样式属性可以单独使用,也可以与其他样式属性结合使用。

Styles can be applied to elements in an HTML document in three different ways. These include “inline styles”, “embedded styles”, and “external style sheets”. Each of these styles are elaborated in more detail below.

样式可以通过三种不同的方式应用于HTML文档中的元素。其中包括“行内样式”、“嵌入样式”和“外部样式表”。下面将详细阐述每种样式。

Inline Styles 行内样式:

Inline styles are applied to a specific HTML element, and the specific style attributes are applied to each element separately.

行内样式应用于特定的HTML元素,特定的样式属性分别应用于每个元素。

Embedded Styles 嵌入样式:

Embedded styles are defined between the an HTML document’s head tags using the style tag. An embedded style can stylize multiple HTML elements in a design. This saves the programer time by eliminating redundant program codes from being written. An HTML document can have more than one embedded style; however each style needs to have its own unique name or identifier.

嵌入样式是使用样式标签在HTML文档的头部标签之间定义的。嵌入式样式可以在设计中设置多个HTML元素的样式。这样可以避免编写冗余的程序代码,从而节省编程人员的时间。一个HTML文档可以有多个嵌入样式;但是,每个样式都需要有自己的唯一名称或标识符。

External Style Sheets 外部样式表:

Large and complicated websites will often use external style sheets to apply styles across multiple HTML documents. The use of external style sheets is the most advanced and effective method to apply styles to multiple HTML documents in a website. This helps to insure that there is consistency between the different elements in the design of a website. The effective Use of external style sheets also reduces how much work the programer needs to do to keep a website up-to-date. If an external style sheet is updated then every HTML document that references that style sheet will also be updated instantly. 

大型和复杂的网站通常会使用外部样式表跨多个HTML文档应用样式。使用外部样式表是将样式应用于网站中多个HTML文档的最先进、最有效的方法。这有助于确保网站设计中不同元素之间的一致性。有效地使用外部样式表还可以减少编程人员为保持网站最新所需的工作量。如果更新了外部样式表,那么引用该样式表的每个HTML文档也将立即更新。

Using Styles 样式的使用:

Although the use of external style sheets is the most effective method of stylizing a website, it is also the most complicated; therefore it is worth while to learn the basics of inline and embedded styles first. Once you understand the basic principles behind the commonly used style attributes it becomes much easier to understand how to create external style sheets for an entire website.

虽然使用外部样式表是设计网站样式最有效的方法,但也是最复杂的方法;因此,首先学习行内样式和嵌入式样式的基础知识也有有必要的。一旦了解了常用样式属性背后的基本原理,就更容易理解如何为整个网站创建外部样式表。

Note: The following examples focus on inline and embedded styles only.

注意:以下示例仅集中于行内样式和嵌入式样式。

Continue on to the first example: Inline Styles