JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

16.1 Overview of CSS

16.1 Overview of CSS

There are many variables in the visual display of an HTML document: fonts, colors, spacing, and so on. The CSS standard enumerates these variables and calls them style properties. CSS defines properties that specify fonts, colors, margins, borders, background images, text alignment, element size, and element position. To define the visual appearance of HTML elements, we specify the value of CSS properties. To do this, follow the name of a property with a colon and a value:

font-weight: bold

In order to fully describe the visual presentation of an element, we usually need to specify the value of more than one property. When multiple name:value pairs are required, they are separated from one another by semicolons:

margin-left: 10%; /* left margin is 10% of page width */ text-indent: .5in; /* indent by 1/2 inch */ font-size: 12pt; /* 12 point font size */

As you can see, CSS ignores comments between /* and */. It does not support comments that begin with //, however.

There are two ways to associate a set of CSS property values with the HTML elements whose presentation they define. The first is by setting the styleattribute of an individual HTML element. This is called the inline style:

This paragraph has increased margins and is surrounded by a rectangular red border.

It is usually much more useful, however, to separate CSS styles from individual HTML elements and define them in a stylesheet. A stylesheet associates sets of style properties with sets of HTML elements that are described using selectors. A selector specifies or “selects” one or more elements of a document, based on element ID, class, or tag name, or on more specialized criteria. Selectors were introduced in §15.2.5 , which also showed how to use querySelectorAll() to obtain the set of elements that match the selector.

The basic element of a CSS stylesheet is a style rule, which consists of a selector followed by a set of CSS properties and their values, enclosed in curly braces. A stylesheet can contain any number of style rules:

p { /* the selector "p" matches all

elements */

text-indent: .5in; /* indent the first line by .5 inches */


.warning { /* Any element with class="warning" */

background-color: yellow; /* gets a yellow background */

border: solid black 5px; /* and a big black border */


A CSS stylesheet can be associated with an HTML document by enclosing it within tags within theof a document. Like theelement, the

Testing, testing

When a stylesheet is to be used by more than one page on a website, it is usually better to store it in its own file, without any enclosing HTML tags. This CSS file can then be included in the HTML page. Unlike theelement, however, theelement does not have a src attribute. To include a stylesheet in an HTML page, use ain theof a document:

Test Document

That, in a nutshell, is how CSS works. There are a few other points about CSS that are worth understanding, however, and the subsections that follow explain them.

友情链接It题库(| 版权归yishouce.com所有| 友链等可联系|粤ICP备16001685号-1