250 likes | 463 Views
Introducing Cascading Style Sheets. With Cascading Style Sheets (CSS), you can create one or more documents that control the appearance of some or all the pages at your Web site Greater consistency in your Web site Easily modified code More flexible formatting
E N D
Introducing Cascading Style Sheets • With Cascading Style Sheets (CSS), you can create one or more documents that control the appearance of some or all the pages at your Web site • Greater consistency in your Web site • Easily modified code • More flexible formatting • Across-the-board compatibility with all browsers is called cross-browser support • No browser supports all features of CSS New Perspectives on Blended HTML, XHTML, and CSS
Comparing HTML Code to CSS Code New Perspectives on Blended HTML, XHTML, and CSS
Creating a CSS Rule • In a text document, type the selector followed by a left brace, as in the following code, and then press the Enter key. selector { • Type the declarations, separating a property from a value with a colon, and then type a semicolon, as in the following code. property:value; • Type a right brace to end the declaration list. The following code shows the syntax for a complete rule selector { property1:value; property2:value; } New Perspectives on Blended HTML, XHTML, and CSS
Guidelines for Writing CSS Rules • When writing CSS rules, make sure you include the following parts of the code: • Left brace before the declaration list • Colon between each property and its value • Semicolon at the end of each declaration • Right brace at the end of the declaration list • Spacing, indentation, line returns, or the position of the braces are irrelevant New Perspectives on Blended HTML, XHTML, and CSS
Using the Three Types of CSS Styles • An external style is one in which you write the CSS code in a document separate from the HTML for the Web page • An embedded style is one in which you write the CSS code in the <head> section of an HTML document • An inline style is one that is written in the <body> section of an HTML document New Perspectives on Blended HTML, XHTML, and CSS
Creating an Embedded Style • Embedded styles apply styles locally to a single Web page New Perspectives on Blended HTML, XHTML, and CSS
Changing the Font • In CSS, styles are grouped according to their function. One of the most commonly used groups is the font properties New Perspectives on Blended HTML, XHTML, and CSS
Changing the Font New Perspectives on Blended HTML, XHTML, and CSS
Changing the Font • You use the font-size property to change the size of type New Perspectives on Blended HTML, XHTML, and CSS
Changing the Font • You use the font-variant property to display lowercase text in small caps, which is smaller than regular capitals • The font-family property changes the typeface New Perspectives on Blended HTML, XHTML, and CSS
Changing the Font New Perspectives on Blended HTML, XHTML, and CSS
Setting Other Properties to Style Text • The CSS line-height property changes vertical spacing between lines of text, a feature not available in HTML • margin property New Perspectives on Blended HTML, XHTML, and CSS
Setting Other Properties to Style Text New Perspectives on Blended HTML, XHTML, and CSS
Using the font Shortcut Property • The font property is a shortcut property, which means you can use it to specify more than one declaration at a time • font-style • font-weight • font-variant • font-size • line-height • margin • font-family New Perspectives on Blended HTML, XHTML, and CSS
Using Color on a Web Page • In HTML code, you can refer to colors in several ways—by name, RGB value, hexadecimal value, or “short hex” value • RGB values are based on the intensity of red, green, and blue • The hexadecimal values for colors represent the intensity of red, green, and blue New Perspectives on Blended HTML, XHTML, and CSS
Using Color on a Web Page New Perspectives on Blended HTML, XHTML, and CSS
Using the color Property • The CSS color property changes the foreground color, which determines the color of text New Perspectives on Blended HTML, XHTML, and CSS
Setting the background-color Property • You use the background-color property to change the background color of an element New Perspectives on Blended HTML, XHTML, and CSS
Grouping Selectors • If you want more than one HTML selector to have similar declarations, you do not have to create a separate rule for each selector New Perspectives on Blended HTML, XHTML, and CSS
Using Contextual (Descendent) Selectors • In HTML, you can nest tags to apply multiple formatting features to the same text • You can nest CSS code by specifying a selector within another selector, which is called a contextual selector New Perspectives on Blended HTML, XHTML, and CSS
Using the display Property • The display property is one of the CSS classification properties New Perspectives on Blended HTML, XHTML, and CSS
Creating and Applying an Inline Style • To create and apply an inline style, you place the style code within the tag in the HTML document where you wish the style to take effect New Perspectives on Blended HTML, XHTML, and CSS
Creating and Applying an Inline Style New Perspectives on Blended HTML, XHTML, and CSS